Question:
What's wrong with this command line string?
the.sidekick
2014-01-24 11:09:24 UTC
I'm trying to use xcopy to copy & paste three files. This string works successfully on the first two, then errors out on the third:

WORKS:
xcopy "C:\Users\%username%\desktop" "U:\Backup\Desktop" /e /i
xcopy "C:\Users\%username%\favorites" "U:\Backup\Favorites" /e /i

FAILS:
xcopy "C:\Users\%username%\My Documents" "U:\Backup\My Documents" /e /i

The error I get is "Access denied" and "Unable to create directory U:\Backup\My Documents"

First, let me start by saying I cannot remove the space from the source, and I've tried removing the space from the destination with no luck. fails with the same error. The "backup" folder is created (empty), so I know that the directory doesn't have any creation restrictions on it.
Three answers:
?
2014-01-24 11:41:18 UTC
It may be that "My Documents" seems to be some type of virtual link to: C:\Users\%username%\Documents. If you look under the Location tab for "My Documents" it gives you can see this path.

The other files you list "desktop" and "favorites" have Locations which match the paths you are using.



So my guess is that "My Documents" is a special link to your Documents folder, and xcopy does not know how to interpret that special link.
plutonic
2014-01-24 19:36:28 UTC
These DOS commands, in my experience are awful cranky.



To get rid of the "Access Denied" stuff you need to open a command prompt in administrative mode. To do this (assuming Windows 7 here) go to Start>Programs>Accessories and look for the DOS prompt. When you see it, right click on the icon and select Run as Administrator.



One other thing you might try in your original third line is to use just Documents instead of My Documents. A lot of these names such as My Documents are symbolic links.



Also if you don't get the results you want try:

xcopy c:\users\|%username%\documents\*.* u:\backup\documents /s



BTW Why are you using %username% instead of your actual username? Are you trying to make it a more general case so that the batch file can be used by anyone to copy only their files?
shiva
2014-01-24 19:21:31 UTC
every thing is correct. but in My Documents you have used the space between My and Document.

it is consider as two strings. so u got this probleam.



use MyDocuments without using white space ur prob. solved



ex:-

xcopy "C:\Users\%username%\MyDocuments" "U:\Backup\MyDocuments" /e /i


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...