Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy directories with spaces in the name

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?

like image 328
Angie Avatar asked Aug 19 '12 16:08

Angie


People also ask

How do you copy a path with spaces?

Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified. The quotation marks must be used.

Can you copy directories?

Alternatively, right-click the folder, select Show more options and then Copy. In Windows 10 and earlier versions, right-click the folder and select Copy, or click Edit and then Copy. Navigate to the location where you want to place the folder and all its contents.

How do you copy all the files from a directory to another directory?

The cp command also copies entire directories into other directories if you specify the -r or -R flags. You can also copy special-device files using the -R flag. Specifying -R causes the special files to be re-created under the new path name.


1 Answers

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.

like image 91
toddk63 Avatar answered Sep 19 '22 17:09

toddk63