Batch copy gives errors, xcopy works fine

Posted by ndm13 on Super User See other posts from Super User or by ndm13
Published on 2014-06-09T02:49:45Z Indexed on 2014/06/09 3:29 UTC
Read the original article Hit count: 427

Filed under:
|
|
|
|

I am writing a general file backup program. It searches the drive for files matching a set of types and then writes them to a folder on the desktop. I wrote it using xcopy on Windows XP but upon learning that xcopy was deprecated in favor of robocopy in Vista and newer, still wanting to maintain compatibility I decided to switch to the non-deprecated copy.

This is where the problems begin. I'm trying to fix the copy routine. I thought I had everything sorted out, but it doesn't copy anything. My output is zero files copied for every iteration.

Original Code using xcopy:

for /r %%a in (*.bmp *.dds *.gif *.jpg *.jpeg *.png *.psd *.pspimage *.tga *.thm *.tif *.tiff) do (
   echo f | xcopy "%%a" "%HOMEDRIVE%%HOMEPATH%\Desktop\LDR\Images\Bitmap\%%~nxa" /q /y /g /c
)

Revised (broken) Code using copy:

for /r %%a in (*.bmp *.dds *.gif *.jpg *.jpeg *.png *.psd *.pspimage *.tga *.thm *.tif *.tiff) do (
   copy "%%a" "%HOMEDRIVE%%HOMEPATH%\Desktop\LDR\Images\Bitmap\%%~nxa" /d /y /z
)

Output:

The system cannot find the path specified.
    0 files copied.

I know that it seems everyone uses either xcopy or robocopy but can anyone help with copy?

Note: I'm using Batch to keep it very lightweight and command-line accessible.

© Super User or respective owner

Related posts about Windows

Related posts about command-line