Windows Server logo small

Merge multiple files into one new file in Windows

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, and here is how:

How to merge or combine multiple files

Here is how to merge a text (.txt) file 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.logCode language: PowerShell (powershell)
copy /a *.txt newfile.txtCode language: PowerShell (powershell)

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.logCode language: PowerShell (powershell)

This is ideal for combining multiple log files into one file for LogParser and IIS log forensics.

Jan Reilink

Hi, my name is Jan. I am not a hacker, coder, developer or guru. I am merely an application manager / systems administrator, doing my daily thing at Embrace - The Human Cloud. In the past I worked for clidn and Vevida. With over 20 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization. I blog at

1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
29/08/2022 08:32

You can use Python for this job, as below:

import shutil
import os
import glob

filenames = glob.glob(‘*.txt’)

with open(‘output_file.txt’,’wb’) as wfd:
for f in filenames:
with open(f,’rb’) as fd:
shutil.copyfileobj(fd, wfd)