6

It it actually possible to get XCOPY to append, as per

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true To append files, specify a single file for destination, but multiple files for source (that is, by using wildcards or file1+file2+file3 format).

?

Neither wildcards or file1+file2+file3 format works for me.

Workaround (sometimes): Use COPY instead.

ChrisJJ
  • 2,191
  • 1
  • 25
  • 38
  • 1
    In my test it will not append - only overwrite the destination file again and again. – foxidrive Aug 28 '14 at 12:55
  • 1
    @foxidrive, same here. – ChrisJJ Aug 28 '14 at 13:12
  • 1
    The + operator only applies to the /exclude command line option, supporting specifying a list of files. Use superuser.com to ask these kind of questions. – Hans Passant Aug 28 '14 at 13:38
  • @Hans "The + operator only applies to the /exclude command line option" The docs are wrong? – ChrisJJ Aug 28 '14 at 14:03
  • No, that's what it says when it explains what /exclude does. – Hans Passant Aug 28 '14 at 14:08
  • "The + operator only applies to the /exclude command line option" "that's what it says when it explains what /exclude does". Actually I do not see it saying that in the explanation of /exclude or anywhere else. And I do see it saying "+" can be used in destination too. – ChrisJJ Aug 29 '14 at 14:23
  • 1
    The documentation in xcopy states `To append files, specify a single file for destination, but multiple files for source (that is, by using wildcards or file1+file2+file3 format)`, but, maybe, while updated, [this](http://support.microsoft.com/kb/114618) is applicable by design – MC ND Aug 29 '14 at 16:28
  • @MC, Thanks. That indicates to my satisfaction that yes the doc statement quoted in my question is faulty. – ChrisJJ Aug 30 '14 at 19:38
  • The MS KB (Microsoft Knowledge Base) link posted earlier by @MCND doesn't work anymore, the latest I could find on Archive.org is http://web.archive.org/web/20150121081805/http://support.microsoft.com/kb/114618 which clearly states **XCOPY Does Not Merge Files** this is *by design in order for XCOPY for Windows NT to be compatible with MS-DOS 5.0* what a pity... – maxxyme Jul 11 '19 at 08:38

2 Answers2

3

If I get it right, you want to merge files into one. For text files I would use:

FOR /R %%f in (file*) DO TYPE %%f >> bigfile
Diodak
  • 80
  • 8
0

The copy command supports concatenation natively:

copy <srcFiles> <destination>

It will list the files as it copies them, and the result will be in the target directory. This is more efficient than using TYPE (which you could also achieve with TYPE file* >> bigfile for the @Diodak answer, rather than using FOR loop.

Example:

C:\Users\f1rum>cd %TMP%
C:\Users\f1rum\AppData\Local\Temp>echo test1 > xxx_test1.txt
C:\Users\f1rum\AppData\Local\Temp>echo test2 > xxx_test2.txt
C:\Users\f1rum\AppData\Local\Temp>echo test4 > xxx_test3.txt
C:\Users\f1rum\AppData\Local\Temp>copy xxx_*.txt merged.txt
xxx_test1.txt
xxx_test2.txt
xxx_test3.txt
        1 file(s) copied.

C:\Users\f1rum\AppData\Local\Temp>type merged.txt
test1
test2
test4
F1Rumors
  • 920
  • 9
  • 13