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.
Asked
Active
Viewed 3.2k times
2 Answers
8
Surround your source specification with quotation marks, as in
xcopy "c:\my documents\some folder\*.*" ...

Robert Harvey
- 178,213
- 47
- 333
- 501
-
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.. – Oct 13 '12 at 19:17
-
1[Echo](http://academic.evergreen.edu/projects/biophysics/technotes/program/batch.htm#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 `*.*`. – Robert Harvey Oct 13 '12 at 19:43
-
You would think that would be the case... but when I use the *.* it says 'File Not Found'. :- – Oct 13 '12 at 21:03
-
Did you Echo the string? Is the resulting path point to an actual folder on the machine? – Robert Harvey Oct 13 '12 at 21:30
-
'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. – Oct 13 '12 at 22:08
-
1It 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? – Robert Harvey Oct 13 '12 at 22:09
-
oh.. it outputs `C:\Users\Sean Webber\My Documents` – Oct 13 '12 at 23:17
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

Ansgar Wiechers
- 193,178
- 25
- 254
- 328
-
Thank You! That did fix my problem! I don't know my Windows would be designed like that, but it works perfectly now :) – Oct 14 '12 at 19:10
-
While this solves the OPs problem, it doesn't answer the question of how do you xcopy directories (in batch variables) with spaces. – TadLewis Sep 06 '18 at 17:40
-
@TadLewis You did notice the double quotes around both path specs, didn't you? – Ansgar Wiechers Sep 06 '18 at 17:47