ROBOCOPY help.. Please

Soldato
Joined
19 Oct 2002
Posts
6,943
Location
Bath
Hi guys i have been using robocopy to backup to my external drive array with no problems for months now and have never had a problem with it.

My problem lies with copying specific folders, or in fact using a right-click >sendto cmd file that looks like this

Code:
@echo off
robocopy %1 k:\music\ /S /E /Z /XF *.jpg /XF *.ini /XF *.db
exit

what this should do is copy the folder selected and right clicked and copy it to k:\music\ (k: is my phones mem card) only problem is that it is not recreating the directory structure, just dumping the files in the music folder on k: other than that it works fine.

I need the directory structure for the player on the phone to detect artist and album.

Can anyone help please what am i missing? any ideas?
 
Either the /S or the /E switch is redundant (actually they conflict with one another: /S copies subdirectories, but not empty ones, /E copies subdirectories *including* empty ones), but the command line should work anyway and it wouldn't cause the effect you describe.

Maybe the problem lies with the phone memory card... what filesystem does it use? Does it fully support long file names, and all the characters in the directory structure you're trying to recreate? Can you drag & drop the same folders OK?

edit: thinking about it, that doesn't really make much sense either... also, I've just copied some folders to a FAT16-formatted flash drive using your exact command line, and it worked OK, so.... :confused:
 
Last edited:
if the %1 = "d:\music\aspects\" it will copy the files within the Aspects folder to the k:\music\ folder but not make the folder Aspects on the target directory and put the files in it. does that make any more sense?

drag and drop is no problem and am currently using terracopy but would rather use robocopy.
 
if the %1 = "d:\music\aspects\" it will copy the files within the Aspects folder to the k:\music\ folder but not make the folder Aspects on the target directory and put the files in it. does that make any more sense?

drag and drop is no problem and am currently using terracopy but would rather use robocopy.
Ah, now I get you... to reproduce the "aspects" folder within "k:\music", "%1" would have to be "d:\music", not "d:\music\aspects".

If you want to cherry-pick folders individually within "d:\music" to send to "k:\music", I don't think it'll work with your batch file - you'd have to manually create corresponding folders within "k:\music", which would rather defeat the object of the exercise...
 
try adding..

MD k:\%~p1

before the robocopy line

And the robocopy line to..

robocopy %1 k:\%~p1 /S /E /Z /XF *.jpg /XF *.ini /XF *.db

though i can't remember off hand if you can do that with variables that are passed like %1 so you may need to set a tmp variable first.
 
nope that dont work either :(

It does and it doesn't all it gives me is the music folder and not the artist folder aswell :(
 
Last edited:
nope that dont work either :(

It does and it doesn't all it gives me is the music folder and not the artist folder aswell :(

OK, try this:

@Echo off
set current=%1
set target="K:%current:~3%
if not exist %target%\nul md %target%
robocopy %1 %target% /S /Z /XF *.jpg /XF *.ini /XF *.db
echo.
echo There must be a simpler way to do this!
pause

:)
 
Ladys and Gentlemen we have cracked it :)

Code:
@echo off
set current=%1
set target="K:\%current:~3%
if not exist %target%\nul" md %target% 
robocopy %1 %target%\ /S /Z /ETA /XF *.jpg /XF *.ini /XF *.db
echo.
echo There must be a simpler way to do this!
pause
exit

job done thanks for your help guys it works just fine now.
 
Last edited:
Ladys and Gentlemen we have cracked it :)


job done thanks for your help guys it works just fine now.
urrggh... hold off on the champagne-cracking, this is more complicated than it looks. :(

I couldn't work out why your extra trailing "s didn't break everything, but it seems %1 will return enclosing quotes when there are spaces in the path, but not otherwise. I tested the script on a folder with spaces in the name, I'm guessing yours had none... the syntax will be wrong for one when it's right for the other.

Still, my head hurts now, and my immediate solution is to have a large scotch, or maybe more than one...

edit: I see you've modified your script a bit, looks like you discovered the same thing... :D
 
yep works for both now mate :) thanks for your help. Am so glad i got an 8gb mem card for my phone instead of another mp3 player :)
 
hmmm... I'm still not convinced it'll work in all cases, but at this stage I don't think I'll argue...

It's just occurred to me that you could simply create a shortcut to "K:\Music" and place it in your SendTo folder (eliminating batch files and robocopy altogether), but obviously having come this far, that would be like admitting defeat. :D
 
glad you got it sorted.

think the problem with my way was I assumed the path would include the folder but thinking about it, it wouldn't. So instead of ...

%~p1

i think it should be...

%~pn1


edit: and %~1, should expand %1 with out quotes, if they cause a problem.
 
Back
Top Bottom