1

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.

8
  • you might find the problem if you insert the word 'echo' before the word 'copy'. And it may arguably make things clearer if you stick an @ here @for and here do @( 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 command
    – barlop
    Jun 9, 2014 at 3:03
  • just a suggestion, think it would work a little easier with "forfiles". e.g : forfiles /p c:\ /s /m *.bmp /c "cmd /c copy @file "%HOMEDRIVE%%HOMEPATH%\Desktop\LDR\Images\Bitmap\%%~nxa" more info here --> ss64.com/nt/forfiles.html
    – deeviate
    Jun 9, 2014 at 3:06
  • @barlop Sorry, that was a revision I posted. The one I thought was totally correct is up now. I caught my mistake after I posted it.
    – ndm13
    Jun 9, 2014 at 3:07
  • 1
    D:\>(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.
    – ndm13
    Jun 9, 2014 at 3:14
  • 1
    Solution found. I'll post the answer when StackExchange lets me. For the record, copy does not create filepaths, so it failed to copy to a path that xcopy would have created for me. I'll have to pre-create my directories I guess.
    – ndm13
    Jun 9, 2014 at 3:23

1 Answer 1

0

Solution finally found!

Apparently xcopy creates directories if they're not specified. I didn't have the \LDR\Images\Bitmap filepath laid out already. copy doesn't know how to make folders so I'll have to generate them beforehand, which is a little annoying because with xcopy it wouldn't make folders when there weren't any files to put in them. With copy I'm making folders assuming they'll be filled.

Thanks for the help. FOR THE RECORD: copy does not create nonexistent file paths. xcopy does!

UPDATE: My final solution. Runs like a champ.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .