Folder Names with Spaces in XCOPY doesn't work?
Asked Answered
S

2

5

Working on a batch script that backs up various important folders on my PC, I have ran into a problem. I can't seem to copy folders that have a space in their name. If there is a sub-folder that has a space and it's parent doesn't, It works perfectly fine. I also seem to be having a problem where I have FULL permission to 'My Documents' folder, but XCOPY won't copy saying 'Access Denied'. Any help is very much appreciated.

Santasantacruz answered 13/10, 2012 at 18:37 Comment(0)
S
8

Surround your source specification with quotation marks, as in

xcopy "c:\my documents\some folder\*.*" ...
Scammony answered 13/10, 2012 at 18:38 Comment(7)
Thanks for the response. I tried that.. well, a little like this: xcopy "%USERPROFILE%\My Documents" "F:\New Folder" /S /E /I and it says 'Is this a file or directory'? You answer directory and it errors..Santasantacruz
Echo that string, and see if it corresponds to an actual folder on the computer. XCopy requires a filespec for the source, not just a folder spec, as in xcopy "%USERPROFILE%\My Documents" "F:\New Folder\*.*" if you want to copy all files from that folder. Notice the *.*.Scammony
You would think that would be the case... but when I use the . it says 'File Not Found'. :-Santasantacruz
Did you Echo the string? Is the resulting path point to an actual folder on the machine?Scammony
'echo' simply means 'Write to console', it doesn't verify anything. It simply writes what you tell it to. So it's going to write it if it's a true path or not.. I think.Santasantacruz
It will output the content of the %USERPROFILE% variable with the rest of the path. You're overlooking something really obvious; how 'bout doing some basic troubleshooting?Scammony
oh.. it outputs C:\Users\Sean Webber\My DocumentsSantasantacruz
B
3

You seem to be using Windows 7 (or Vista). On those systems My Documents is a symbolic link that only exists for backwards compatibility and cannot be accessed by users. The actual location of your documents folder is C:\Users\Sean Webber\Documents. Change your script to

xcopy "%USERPROFILE%\Documents" "F:\New Folder" /s /e /i
Butterfat answered 14/10, 2012 at 15:1 Comment(3)
Thank You! That did fix my problem! I don't know my Windows would be designed like that, but it works perfectly now :)Santasantacruz
While this solves the OPs problem, it doesn't answer the question of how do you xcopy directories (in batch variables) with spaces.Sacrosanct
@Sacrosanct You did notice the double quotes around both path specs, didn't you?Butterfat

© 2022 - 2024 — McMap. All rights reserved.