Windows – Concatenate multiple files with Windows command line

command lineconcatenationwindows

I use below two commands to concatenate multiple files from different directories:

  1. Method 1

    type "C:\folder1\file1.txt" "C:\folder2\file2.txt" > output.txt

  2. Method 2

    copy "C:\folder1\file1.txt"+"C:\folder2\file2.txt" output.txt

However, the output file in Method 1 contains EOF at the end of every single file. How to get rid of the EOF?

Best Answer

Concatenate Multiple files into One File Create Test Files

E:\Work\>for %x in (1 2 3 4) do echo %x > %x.txt

        E:\Work\>echo 1   1>1.txt

        E:\Work\>echo 2   1>2.txt

        E:\Work\>echo 3   1>3.txt

        E:\Work\>echo 4   1>4.txt

Verify test file creation

E:\Work\>dir *.txt

        Directory of E:\Work\

        2017-04-26  02:53 PM                 5 1.txt
        2017-04-26  02:53 PM                 5 2.txt
        2017-04-26  02:53 PM                 5 3.txt
        2017-04-26  02:53 PM                 5 4.txt

Concatenate files

E:\Work\>copy /b ?.txt concatenation.txt

        1.txt
        2.txt
        3.txt
        4.txt
                1 file(s) copied.

Verify concatenated file creation

E:\Work\>dir *.txt

        Directory of E:\Work\

        2017-04-26  02:53 PM                 5 1.txt
        2017-04-26  02:53 PM                 5 2.txt
        2017-04-26  02:53 PM                 5 3.txt
        2017-04-26  02:53 PM                 5 4.txt
        2017-04-26  02:54 PM                20 concatenation.txt

Verify correct contents of concatenated files

E:\Work\>type concatenation.txt

        1
        2
        3
        4
Related Question