Copy the Contents of Multiple Files into Single File or Merge Multiple Files into Single File

Problem:

I was facing a situation wherein I had hundreds of files lying around and had to take printout of all the files. Having to take printout of each and every file proved to be nightmare.

Solution:

The solution was to merge all the files into a single file or copy the contents of multiple files into single file.

Before issuing these commands at the command prompt change to the directory where all the files are present.The code shown below copies the contents from all the files ending with py extension into a new file called mergedFile.doc. The reason I created a word doc file is it’ll be easier to take printout and had no reason to think otherwise.

copy /b *.py mergedFile.doc

If I want to merge multiple text files into a single document file

copy /b *.txt mergedFile.doc

If I want to merge multiple text files into a single text file

copy /b *.txt mergedFile.txt

If I want to merge multiple java files into a single document file

copy /b *.java mergedFile.doc

Code shown here is tested on Windows 7/8/10 machine.

Leave a Reply

Your email address will not be published. Required fields are marked *