I am trying to create a single file by appending multiple files in a folder. In between the files i wanted to add a new line character . I have tried out the below but it does not work. Please suggest what am i missing.
Get-ChildItem -Filter *.sql |sort CreationTime| % { Get-Content $_ -ReadCount 0 | Add-Content combined_files.sql| Add-Content combined_files.sql -value `n"dummy text before next file" }
I am able to get the combined_files.sql created with the contents of child files but the text inbetween files is missing. Please suggest.
CodePudding user response:
Try constructing your data before writing it out
Get-ChildItem -Filter *.sql | Sort-Object CreationTime | ForEach-Object {
$ThisFile = (Get-Content $_.FullName) "`ndummy text before next file"
Add-Content -Path combined_files.sql -Value $Thisfile
}
