I have a directory of subfolders. Each one contains text files within it. I am trying to combine the files found in each subfolder.
Example:
SubFolder 1 → a.txt + b.txt + c.txt → SubFolder1Merged.txt
SubFolder 2 → x.txt + y.txt + z.txt → SubFolder2Merged.txt
I have referenced this thread.
This is what I have so far:
$startingDir = "C:\Users\WP\Desktop\TextFiles"
function CombineLogs {
param([string]$startingDir)
dir $startingDir -Filter *.txt | Get-Content |
Out-File (Join-Path $startingDir COMBINED.txt)
dir $startingDir | ?{ $_.PsIsContainer } | %{ CombineLogs $_.FullName }
}
CombineLogs 'C:\Users\WP\Desktop\CombinedTextFiles' #output the combined text files here
I get a combined.txt generated in CombinedTextFiles - but not individual files merged.
Also the file is empty.
I simply want to loop through each subfolder, merge the text files within each folder, then output to my CombinedTextfiles Folder.