Is there a way to combine text files using the Windows command line?

7

2

I am thinking looking for a way to combine all the .txt files in a directory into a single one .txt file.

Is there a way to combine text files using the Windows command line?

DanC

Posted 2010-09-21T18:56:05.470

Reputation: 337

Answers

20

You can also use the copy command, eg

copy *.js bigfile.txt

or, for specific files

copy file1.txt+file2.txt+file3.txt bigfile.txt

Neal

Posted 2010-09-21T18:56:05.470

Reputation: 8 447

+1 - This also allows you to decide what order to have the combined result set in. – JNK – 2010-09-21T20:51:45.817

1

This included the BOM in my textfiles so I fixed it my using type commando (see DanC's answer) (http://superuser.com/a/191234/56861).

– Torbjörn Hansson – 2012-09-12T11:42:00.803

8

type * > someotherpath/all.txt

The need for creating the file somewhere else is that if the new file is created on the same folder, it should be excluded from the selection.

Also, filtering by extension and using a different one for the resulting file would work. For example:

type *.js > all.txt

DanC

Posted 2010-09-21T18:56:05.470

Reputation: 337