Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

an arrow → character getting appeded to files in a .bat script

Tags:

batch-file

The following script gets all files with .new_tmp extension and copies them to a file with the same name but without the .new_tmp extension. In addition a comment is placed at the top of the file and the .new_tmp file is deleted.

echo ^<?php /* > start.tmp
echo */ ?^> > end.tmp
for /R "./mydir" %%I in (*.new_tmp) do (
    copy start.tmp+license.txt+end.tmp+%%I worker.tmp
    move worker.tmp %%~pI%%~nI
    del %%I
)

The problem is that a right facing arrow → gets appended to the bottom of all the files

Why is this character getting appended to the end of all the files?

UPDATE I tried this with a much simpler example and got the same results

copy NUL worker.tmp
copy worker.tmp + license.txt + license.txt + license.txt

Same problem, an arrow at the end...

I am running under Windows 7

like image 509
jax Avatar asked Jun 11 '11 04:06

jax


2 Answers

The arrow is a CTRL-Z ascii char that is appended by the COPY command when used to concatenate files with the + option.

To prevent COPY to append the CTRL-Z character, use COPY /B for a binary copy.

So, your command would be

COPY /B start.tmp+license.txt+end.tmp+%%I worker.tmp
like image 151
PA. Avatar answered Oct 02 '22 08:10

PA.


When /b follows Destination, copy does not add an end-of-file character.

This is how I would solve the problem:

COPY start.tmp+license.txt+end.tmp+%%I worker.tmp /B
like image 32
Schneidenheimer Avatar answered Oct 02 '22 07:10

Schneidenheimer