1

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?

4
  • What if you execute type c:\folder1\file1.txt > output.txt & type c:\folder2\file2.txt >> output.txt ?
    – Mark Allen
    Commented Aug 17, 2015 at 18:28
  • @MarkAllen it works. it doesn't have EOF in the middle of the output file Commented Aug 18, 2015 at 0:51
  • @Sun I'm using windows Commented Jun 9, 2016 at 17:25
  • @Sun Windows 8.1 Pro Commented Jun 10, 2016 at 8:48

2 Answers 2

3

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
1
  • Works for me: copy /b *.txt concatenation.txt
    – pkSML
    Commented Feb 19, 2019 at 3:39
1

For me it is the method 2 with COPY that causes the EOF to be added, not the TYPE way. You can tell COPY to copy the files as binary with the /B flag. Then the output will be exactly the files and nothing more.

1
  • It's strange. I'm on win8.1. COPY doesn't include any EOF in the middle of the output file. Commented Aug 18, 2015 at 0:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .