Copying files using Copy in batch script copies only the first file to the destination folder

StackOverflow https://stackoverflow.com/questions/10831290

  •  11-06-2021
  •  | 
  •  

Question

This is my copy command :

set POLL="C:\Documents and Settings\"
copy Register.class+Ca.class+pack %POLL% /-Y

pack is a folder here.
The result of the above copy coman is that only Register.class gets copied to the destination folder. What's my mistake?

Was it helpful?

Solution

Naming multiple source files for a copy command copies the files into one single file.

copy fileone + filetwo filethree

would result in filethree containing the content of fileone AND filetwo. You cannot copy multiple files to a different location with copy.

However it is fairly easy to do so using either a loop or xcopy-command:

set POLL="C:\Documents and Settings\"
FOR %%F IN (Register.class Ca.class) DO copy %%F %POLL% /-Y
xcopy pack %POLL% /-Y
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top