Concatenate files with command line Windows 7

Problem

If you need to concatenate 100 text files in one folder. You don't know the file names and you want to do it automatically you can use windows command line.

Solution 1 Using Copy command for text files

  • Open Command Line
  • On keyboard press: WINDOWS + R
  • type cmd
  • Press Enter
  • Or in Start Menu write cmd and open cmd.exe
  • Go the your folder with

cd C:/folderWithTextFiles

  • Type

copy /b *.txt concatenatedFile.txt

In the folder: C:/folderWithTextFiles you will have file named concatenatedFile.txt which will have all the information concatenated ( from all files ending with txt)

Solution 2 Concatenate CSV files

  • Open Command Line(check Solution 1 how to open it)
  • Go the your folder with

cd C:/folderWithTextFiles

  • Type

copy /b *.csv concatenatedFile.csv

Solution 3 Use type command

  • Open Command Line(check Solution 1 how to open it)
  • Go the your folder with

cd C:/folderWithTextFiles

  • Type

type *.txt > concatenatedFile.txt

Solution 4 Concatenate with loop

  • Open Command Line(check Solution 1 how to open it)
  • Go the your folder with

cd C:/folderWithTextFiles

  • Type

for %x in (*.txt) do copy /b *.txt concatenatedFile.txt

Solution 5 Concatenate without N first lines(headers)

If the files have headers and you want to skip them then or you need to start concatenation from line n than you can do:

  • go to the folder with the text files
  • create folder out
  • Type the command

for %x in (*.txt) do more +2 %x > out/%x

  • command below will start from line 2
  • for each text file it will create text file in folder out which will be the text starting from line 2
  • go to folder out with:

cd out

  • Do concatenation from Solution 1

Note

If you you concatenated the information in a text file and then you want to concatenate it again in another file you can have duplication. So you can change the output file type to .log, .tmp and so on.

type *.txt > concatenatedFile.log

Or simply delete the output file at every execution.

Related Article