Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
If you need to combine text files in cmd.exe, you would issue the following command:
copy file1.txt+file2.txt+file3.txt combined_files.txt
If you wish to do the same for binary files, you would use the following command:
copy /b file1.bin+file2.bin+file3.bin combined_files.bin
To do the same in PowerShell is pretty straightforward. If the destination file does not already exist or already contains content, you’ll want to issue the New-Item command first. If you know it doesn’t exist or is empty, you can skip that line, below.
New-Item -ItemType file ".\combined_files.txt" –force
Get-Content .\file?.txt | Add-Content .\combined_files.txt
Thanks to Gerardo Lopez for his “Combine or Join Two Text Files Using PowerShell” article, which is the basis for this information.
Rob
Anonymous
January 22, 2014
I'd suggest another algorythm for BIG files. I tried your version for 30 files with a sum of 1,6 GB data and ran into a RAM limitation.
New-Item -ItemType file ".combined_files.txt" –force
Get-ChildItem -filter "file?.txt" | %{ Get-Content $_ | Add-Content .combined_files.txt }
Anonymous
April 12, 2014
The comment has been removed
Anonymous
May 21, 2014
Thanks to both of you for the feedback!
Anonymous
November 02, 2014
None of your items worked for me. This is what actually worked since I just used it:
Get-ChildItem -recurse -include "*.txt" | % { Get-Content $_ -ReadCount 0 | Add-Content .combined_files.txt }
Anonymous
May 06, 2016
Hi Robert,Just found this very useful post. Any advice on how to exclude the header row for all files except the first?
Anonymous
June 29, 2016
The comment has been removed
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in