Merge multiple files into one new file in Windows

Date posted: 2017-05-16
Last updated: 2026-10-04

A quicky: merge or concatenate multiple text or log files into one new file in Windows, using copy in cmd.exe or Get-Content in PowerShell.

A quicky: if you need to merge - or concatenate - multiple text files into one new file in Windows, you can use the copy command in cmd.exe. Here is how.

In cmd.exe, copy /b *.log newfile.log merges all matching files into one new file. In PowerShell, pipe Get-Content into Set-Content to do the same.

How to merge or combine multiple files

Here is how to merge text (.txt) files in the Windows command-line (cmd.exe) environment.

In your Windows cmd.exe command-line, use the following single command to merge all text files in a directory into one new file:

copy /b *.log newfile.log
copy /a *.txt newfile.txt

The copy parameters /a and /b indicate ASCII text or binary files.

Concatenate two text files in PowerShell?

In PowerShell you can use the Get-Content and Set-Content cmdlets to concatenate two (or more) files into one new file. For example:

Get-Content *.log | Set-Content newfile.log

# Get-Content logfile1.log, logfile2.log, logfile3.log | Set-Content newfile.log

This is ideal for combining multiple log files into one file for LogParser and grep forensic log parsing of IIS log files.

On Linux, too many files for one command? Here is how to grep through a large number of files in Bash (argument list too long).

I write these posts in my spare time, based on real problems from my day job as a sysadmin. If this one saved you some debugging time, a small donation is much appreciated. Thanks! 🙏

Leave a Comment