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.
@for
and heredo @(
that should list all the commands and you may see whatever flaw. I notice also you are missing double quotes in your copy command. You had them in your xcopy commandD:\>(copy "D:\Program Files\Winamp\Plugins\avs\whacko6-07.bmp" "C:\Documents and Settings\,,,,\Desktop\LDR\Images\Bitmap\whacko6-07.bmp" /d /y /z ) The system cannot find the path specified. 0 file(s) copied.
A sample on a test drive D. The results were all the same.copy
does not create filepaths, so it failed to copy to a path thatxcopy
would have created for me. I'll have to pre-create my directories I guess.