Reputation: 3640
I have a .bat file that generates a file from some previous commands, i need to add to this .bat file some dos commands that append the content of this file to another file, the names of the sourcefile and of the targetfile are fixed and both are text files.
There can be cases where the source file is not created from the commands on the .bat so maybe it is possible to add a check on this condition before executing the append command?
How can i do this?
I tried copy target+source target
but sometimes using this i find the target file with some extra characters at line start, i don't know why.
Thanks
Upvotes: 1
Views: 6746
Reputation: 51226
You cannot directly copy on top of the original file(s). Also make sure you use the /B
switch for COPY
to copy using "binary mode" -- failing to do this has the following negative consequences:
Example of how to do it right:
copy /B input1 + input2 output
move /Y output input1
The move
command moves the file output
back on top of input1
; /Y
suppresses the "Overwrite?" prompt you would otherwise see.
Upvotes: 1
Reputation: 532
If your text was encoded UTF-8 or UTF-16, Maybe extra characters is BOM(Byte Order Mark)?
BOM exists start of file and has 3 byte length.
Is it match your probrem?
Upvotes: 0