Folder Names with Spaces in XCOPY doesn't work?
Solution 1
Surround your source specification with quotation marks, as in
xcopy "c:\my documents\some folder\*.*" ...
Solution 2
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
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
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.
-
Admin over 11 yearsThanks 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.. -
Yinda Yin over 11 yearsEcho 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*.*
. -
Admin over 11 yearsYou would think that would be the case... but when I use the . it says 'File Not Found'. :-
-
Yinda Yin over 11 yearsDid you Echo the string? Is the resulting path point to an actual folder on the machine?
-
Admin over 11 years'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.
-
Yinda Yin over 11 yearsIt 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? -
Admin over 11 yearsoh.. it outputs
C:\Users\Sean Webber\My Documents
-
Admin over 11 yearsThank You! That did fix my problem! I don't know my Windows would be designed like that, but it works perfectly now :)
-
TadLewis over 5 yearsWhile this solves the OPs problem, it doesn't answer the question of how do you xcopy directories (in batch variables) with spaces.
-
Ansgar Wiechers over 5 years@TadLewis You did notice the double quotes around both path specs, didn't you?