Here it's a powershell script that consolidate all file in a folder to a file "_allFilesInOne.txt". Just put this file GetAllFilesInOne_ps1.txt in a folder and run it (renamed it .ps1 before)
#
# Get All Files In One File
#
# F.Richard
# 2010 June
#
$appendfile = "_allFilesInOne.txt"
$files = Get-ChildItem * -exclude $appendfile,$MyInvocation.MyCommand.Name -include *
$Content = ""
$Content | Out-File $appendfile
ForEach ($filename in $files) {
Write-Host $filename
$Content = Get-Content $filename
$Content | Out-File -append $appendfile
}
You can improve this script easily.
For example, you can exclude .log files by changing
-exclude $appendfile,$MyInvocation.MyCommand.Name
by
-exclude $appendfile,$MyInvocation.MyCommand.Name,*.log
You can can also change inclusion of all files to only .txt files by changing
-include *
by
-include *.txt
No comments:
Post a Comment