Using the DOS copy command syntax to concatenate files:

copy file1.txt+file2.txt all.txt

I know I can do this...

copy file1.txt+file2.txt file1.txt

Is this efficient? Is it doing what I'm expecting? It works, but I want to know is it actually appending to file1.txt or is it copying file1.txt (bad), concatenating file2 and then renaming to file1.txt (which is not efficient)?

link|improve this question
As a side note, remember that you need to use the "/b" switch if you ever decide to use copy to cat binary files. – Brian Knoblauch Jul 23 '10 at 18:43
feedback

1 Answer

up vote 3 down vote accepted

copy is copying file1.txt and file2.txt into memory, concatenating them then writing out to file1.txt. It's not copying to a new file then renaming that file so really there's not much extra disk I/O.

You can also use type.

type file2.txt >> file1.txt

The >> operator appends text. But that will, of course, not work for binary files.

link|improve this answer
2  
it should work fine for binary files. it's just not generally useful, because most binary data formats use some form of encapsulation such that even in the combined file, only the first file will be recognized & used. if you had, say, 2 raw PCM files, this would be a fine way to concatenate them (as opposed to 2 WAV files, where another program is needed to alter headers). – quack quixote Nov 30 '09 at 17:56
I was using the term renaming very loosely. If file1 and file2 are huge files I want file2 appended to file1 WITHOUT copying any file1 data (it is too big to copy again). Tyler, you have suggested it will copy file1.txt data. Using the type command, this will actually append? Thanks. – clsturgeon Nov 30 '09 at 18:06
Be warned, though that old DOS versions failed to copy a target to the target with copy source+otherfile source. It resulted in a 64 kB source file because a 64 kB buffer was used for reading and writing, and after the first flush, the source was just 64 kB :-) no joke. – TheBlastOne Mar 9 at 8:22
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.