Any PDF file data ends with "%%EOF" (without the quotes).
Most pdf generators append a newline character, which not needed and ignored because it is located after the data.
The same happens to any other character that is appended at the end of the pdf file.
So appending an EOF marker is not the main problem here.
But if the file contains an EOF marker (0x1A) somewhere within the file, then the copy command finishes at this marker.
The rest of the file will not be copied.
In WinXp home this happens (for example) if you are using wildcards for the source, and a filename for the destination argument.
If the destination is a directory, then the file is completely copied.
But this behaviour may be OS specific.
More info:
https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/copy.mspx?mfr=true.
So this happens in detail (using WinXP home):
Compo wrote:Would changing the copy command to read COPY /A prevent the reported corruption.
No this copy mode (that is selected automatically by copy) causes the corruption, so the following happens:
Code: Select all
If Not Exist "%~1%_ext%" Copy /A "%~1\*%_ext%" "%~1%_ext%">Nul
This "/A" indicates that all files are text files.
The destination file ends with the first EOF marker.
Code: Select all
If Not Exist "%~1%_ext%" Copy "%~1\*%_ext%" /A "%~1%_ext%">Nul
This "/A" indicates that the source file is a text file.
The destination file ends with the first EOF marker, too.
Code: Select all
If Not Exist "%~1%_ext%" Copy "%~1\*%_ext%" "%~1%_ext%" /B>Nul
This "\B" indicates that copy does not add an end of file character.
As the source file is automatically selected to be a text file, this results in a file that ends one byte earlier than the files above.
So this is what you wanted to to (treat all files as binary files):
Code: Select all
If Not Exist "%~1%_ext%" Copy /B "%~1\*%_ext%" "%~1%_ext%">Nul
penpen