I am trying to use robocopy but am unable to make it work because of spaces in the directory names.
I am trying to copy 3 directories: My Documents, My Music and My Pictures to 'C:\test-backup' but want the end result to be
'C:\test-backup\My Documents'
'C:\test-backup\My Music'
'C:\test-backup\My Pictures'
My command does not work:
robocopy C:\Users\Angie C:\test-backup "My Documents" /B /E /R:0 /CREATE /NP /TEE /XJ /LOG+:"CompleteBackupLog.txt"
No matter what I do, it’s just not happening. Anybody have any suggestions or tricks?
What's with separating My Documents
from C:\test-backup
? And why the quotes only around My Documents
?
I'm assuming it's a typo, try using robocopy C:\Users\Angie "C:\test-backup\My Documents" /B /E /R:0 /CREATE /NP /TEE /XJ /LOG+:"CompleteBackupLog.txt"
[Edit:] Since the syntax the documentation specifies (robocopy <Source> <Destination> [<File>[ ...]]
) says File, it might not work with Folders.
You'll have to userobocopy "C:\Users\Angie\My Documents" "C:\test-backup\My Documents" /B /E /R:0 /CREATE /NP /TEE /XJ /LOG+:"CompleteBackupLog.txt"
You should write brackets only before path: "c:\program files\
robocopy "C:\Users\Angie\My Documents" "C:\test-backup\My Documents" /B /E /R:0 /CREATE /NP /TEE /XJ /LOG+:"CompleteBackupLog.txt"
robocopy "C:\Users\Angie\My Music" "C:\test-backup\My Music" /B /E /R:0 /CREATE /NP /TEE /XJ /LOG+:"CompleteBackupLog.txt"
robocopy "C:\Users\Angie\My Pictures" "C:\test-backup\My Pictures" /B /E /R:0 /CREATE /NP /TEE /XJ /LOG+:"CompleteBackupLog.txt"
There's no need to add space before closing quote if path doesn't contain trailing backslash, so following command should work:
robocopy "C:\Source Path" "C:\Destination Path" /option1 /option2...
But, following will not work:
robocopy "C:\Source Path\" "C:\Destination Path\" /option1 /option2...
This is due to the escaping issue that is described here:
The \ escape can cause problems with quoted directory paths that contain a trailing backslash because the closing quote " at the end of the line will be escaped \".
If this folder is the first in the command then it won't work with a space in the folder name, so replace the space in the folder name with an underscore.
When you specify the last Directory on the path remove the last .
for example "\server\directory with space\directory with space".
that should do it.
There is a bug in robocopy in interpreting the source name. If you include a back slash at the end of the path to describe a folder it keeps including the string for the source into the rest of the line. ie
robocopy "C:\back up\" %destination% /e Nothing here will go to the destination string
robocopy "C:\back up" %destination% /e but this works
I may be wrong but I think both should work!
After some trial and error and observing the results (in other words, I hacked it), I got it to work.
Quotes ARE required to use a path name with spaces. The trick is there MUST be a space after the path names before the closing quote...like this...
robocopy "C:\Source Path " "C:\Destination Path " /option1 /option2...
This almost seems like a bug and certainly not very intuitive.
Todd K.
Source: Stackoverflow.com