Folder Names with Spaces in XCOPY doesn't work?

28,204

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
Share:
28,204
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    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
    Admin over 11 years
    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..
  • Yinda Yin
    Yinda Yin over 11 years
    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 *.*.
  • Admin
    Admin over 11 years
    You would think that would be the case... but when I use the . it says 'File Not Found'. :-
  • Yinda Yin
    Yinda Yin over 11 years
    Did you Echo the string? Is the resulting path point to an actual folder on the machine?
  • Admin
    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
    Yinda Yin over 11 years
    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?
  • Admin
    Admin over 11 years
    oh.. it outputs C:\Users\Sean Webber\My Documents
  • Admin
    Admin over 11 years
    Thank You! That did fix my problem! I don't know my Windows would be designed like that, but it works perfectly now :)
  • TadLewis
    TadLewis over 5 years
    While this solves the OPs problem, it doesn't answer the question of how do you xcopy directories (in batch variables) with spaces.
  • Ansgar Wiechers
    Ansgar Wiechers over 5 years
    @TadLewis You did notice the double quotes around both path specs, didn't you?