cannot copy file using xcopy, that has a % in the file name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Running XpSp2, fully patched. I am trying to copy a file that has a '%'
symbol in it ( say the file name is: #$%3fw.txt) and using xcopy from a batch
file and it will not copy. I get a message back that file #$fw.txt is not
found. There are no spaces in the UNC path to the file and it does not matter
if the path is in double or single quotes.

The strange thing, is if I take it out of the batch file and just copy it
into an existing command shell, it copies fine. So what is the difference
from using xcopy from a batch file compared to a command shell?
 
You need to double the %.
If your file is named "#$%3fw.txt", use "#$%%3fw.txt" to avoid the
"environment variable replacement" confusion...
 
I think the OP needs to escape the % character rather
than doubling it:

xcopy c:\#$^%3fw.txt d:\
 
Thanks for the information, but I cannot remove the % from the file name, and
changing the file name may not be the best option for me in this case.
 
Use wildcards!

BTW: I was wrong with my escape character (because
I only tested it in a Command Prompt environment). In
a batch file the suggestion made by PapaDos is the
correct way to resolve the problem.
 
Back
Top