Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to run the following

copy %HOMEPATH%\"My Documents"\test.txt %CD% 

from c:\backupSettings

I get the error:

Access is denied. 0 file(s) copied.

share|improve this question
Try running from an elevated command prompt. – HackToHell Mar 24 '12 at 15:45
I tried that and the visual studio command prompt run as administrator. Nothing seems to work. – RBZ Mar 24 '12 at 15:51
Just so you know, when using command-line file utilities you can reference the current directory with . instead of using %CD%. So copy C:\Folder\*.* . copies all files from the directory 'Folder' to the current directory. Also, .. always represents the parent of the current directory. – Ƭᴇcʜιᴇ007 Mar 24 '12 at 18:11
up vote 4 down vote accepted

Your issue is the command:

copy %HOMEPATH%\"My Documents"\test.txt %CD% 

It should be:

copy %HOMEPATH%\Documents\test.txt %CD% 

Since Windows Vista the documents folder was renamed. Windows 7 introduced some weird feature that shows it as "My Documents", but the underlying path (which you must use from the command line) is "Documents".

Actually, it gets even more confusing. Vista put a symbolic link called "My Documents" in the profile folder, so legacy applications would still work. Access is denied under normal circumstances, and it should not be used, touched, modified, etc. Windows 7 keeps that symbolic link, but also shows the "Documents" folder as "My Documents". If you show hidden/system filed, you'll actually see two "My Documents" folders in your profile in Windows 7 - one is a mask put on the "Documents" folder while the other is the symbolic link. The symbolic link is the one you're actually trying to navigate to when you go to the path %HOMEPATH%\My Documents\, and of course that is forbidden.

Also, I don't think you can put quotes in the middle of a path. You should put them around the whole path, e.g.:

copy "%HOMEPATH%\Documents\test.txt" "%CD%" 
share|improve this answer

You can take owenership of the folder, using this script. See if you have any errors after doing that.

share|improve this answer
this looks useful, but I can't go around running this script on random machines. – RBZ Mar 24 '12 at 16:14
@Kaizen thought it was a problem with permissions, dumb me ;p – HackToHell Mar 24 '12 at 16:16
it is a good script, but it is good practice to avoid side effects. – RBZ Mar 24 '12 at 16:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .