I don't understand the behaviour of the COPY command when using a wildcard.
I have a single text file in C:\Source
called mpt*.asm
and I want to copy it to C:\Dest
. This is needed from a batch script, and I can't be sure of the exact name of mpt*.asm
(it may be mpt001.asm
for example). The destination name should be exactly mpt.asm.
If I use:
COPY C:\Source\mpt*.asm C:\Dest\mpt.asm
The file file is copied, but has a extra (0x1A
) character appended to the end of the file.
If I use:
COPY C:\Source\mpt*.asm C:\Dest\mpt.asm /B
I don't get this spurious character.
If I don't use a wildcard, I don't get the spurious character either. It seems unlikely there is a bug in COPY
, but this behavior seems unexpected.
Is there a way of doing this copy without resorting to using /B
?
You can use the wildcard characters asterisk ( * ) and question mark ( ? ) as part of the file name argument. For example, part* loads the files part-0000 , part-0001 , and so on. If you specify only a folder name, COPY attempts to load all files in the folder.
If source is a directory or contains wildcards and destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether destination is a file or a directory.
As an alternative to entering a new name for each file, you can use a simple wildcard system to rename all copied or moved files at once. This is not a full pattern matching (or regular expressions) system; instead, the only wildcard character that's recognised is * (the asterisk).
I have never seen that before, but it does append an extra arrow character for me too.
You can work around the issue using xcopy
instead.
echo f| xcopy C:\Source\mpt*.asm C:\Dest\mpt.asm
If you read copy /?
it says
To append files, specify a single file for destination, but multiple files for source (using wildcards or file1+file2+file3 format).
So by using a single filename as the the dest, and using a wildcard in the source, it may interpret that as appending, which may be what the extra character is for, but as you aren't appending anything you can see it.
I'm only guessing but that may explain it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With