27 April 2016

How to Merge Multiple Files Using Command Prompt

Leave a Comment
Merge Multiple Files Using CMD

Did you ever tried to merge two or more files? Well If you're a programmer, you might have tried to merge words in C++ or Python. In the same way, we can combine two or more files into a single unit. This can be possible with the help of Windows Command Prompt. In this tutorial, I will guide you how to do that. Lets divided it in two parts. In first part, we will discuss on how to merge txt files and then, we will merge two different format files with the same approach.

Merging text (.txt) files


This is one of the easiest way of merging. Here we will merge two or more text files so as to get their data in one single file. The basic logic behind this tricks is very simple.
  • First of all, copy all txt files (that you want to merge) and paste them in new folder. Now rename that folder as "Files" and move it to your Desktop.
  • Our next aim is to open the Command Prompt and move it to the folder location where all files are saved. For this task, we will use "cd" command. The basic syntax is - "cd [folder location here]"
  • At last, we will use "copy" command. This command let you copy one or more files to a particular location. The basic syntax that we'll use is - "copy /b *.txt final-text.txt"

    Here "/b" is a parameter which indicates a binary file, asterisk (*) is a wildcard which is used to select all txt format files and "final-text.txt" is the name of new file that contains the merged data.
Now I just hope that you have a basic understanding about this tricks. To merge your txt files, follow these simple steps -
  1. Go to start menu and open Command Prompt (Search for "cmd.exe" or use run command).
  2. Now type this code -
    cd C:\Users\[Username]\Desktop\Files
    This will move the Command Prompt to "Files" folder that you had already saved on Desktop. Please change the username with your account name. You can find it by executing "echo %username%" code in new cmd window. Alternatively, you can find out the complete folder location from its properties.
  3. Finally type this copy command and press Enter button -
    copy /b *.txt final-text.txt
    Merge .txt Format Files
That's it. Now open the folder and you'll find a new text file their (named as final-text.txt). This new file contains the text of all merged files. For example, If you've two txt format files having "I am a" and "Superman" words respectively then the new file will contain both these words one after another like "I am a Superman". This order can be opposite If the file containing "Superman " will come first. Then the new text will be "Superman I am a". (which is meaningless here)

You must arrange the txt files in the order of data that you want after merging. This can be done by renaming. For example, If you want any txt file to come first, rename it to "1.txt" and then rename other file to 2, 3, 4 and so on. This will automatically arrange the files one after another in your desired order.

Also Read: How to rename multiple files at once in Windows

You can also select specific files by using plus (+) operator between them. For example, If you've two files named as "text1.txt" and "text2.txt" then you can use this code to merge them -


copy /b text1.txt+text2.txt final-text.txt

Merging 2 different format files


You can also merge two different format files with the same approach and interesting thing is, this will help you to hide your private data. The basic syntax is same as in above code. Just change the file name and format type. For example,

copy /b file1.txt+file2.rar final-file.rar

Above code will merge txt and rar into a single file (named as final-file) that has rar format. If you'll open this rar file, it will show all the data of file2. Now If you want to see the file1 data, simply change the format of final-file to ".txt" and open it again. Format can be changed by renaming it.

So basically, above code will hide the data of file1 in rar file and thus no one can open it expect you. You can also change this order by changing the format of final-file to ".txt". Another amazing thing that I had observed is the size of new file. The new file size will be the sum of both file sizes. For example, If the txt file above has 1 MB size (though it is very large) and rar file is of 5 MB then the size of final-file will be 6MB.

In this same way, you can also hide your videos, pdf and images content. Few other examples are as follows -

  • copy /b image.jpg+compressed.rar hidden.rar
  • copy /b presentation.pdf+compressed.rar hidden.rar
  • copy /b video.mp4+compressed.rar hidden.rar
Note: I had combined all files with rar file only. If you'll combine them with any other format, it may result into error or your file may not open. The easiest way to hide any file is by merging it with rar format file.

Now tell me what will happen, if you'll merge two same format files (I am not taking about txt). Say two mp4 format videos! Will it join both videos one after another and creates a new one with their total length? No! Same thing is possible for txt files but not for other formats and instead of this, new file will be the exact copy of either video. Lets take this example -


copy /b video1.mp4 video2.mp4 final-video.mp4

Here final-video will be the same video as video1 but its size will the sum of both videos. Try other formats yourself. Although I had tried my best to make this tutorial simple but still If you've any doubts, please drop them in below comment box. Stay tuned for more interesting updates.

Leave A Comment