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

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?
 
G

Guest

You need to double the %.
If your file is named "#$%3fw.txt", use "#$%%3fw.txt" to avoid the
"environment variable replacement" confusion...
 
P

Pegasus \(MVP\)

I think the OP needs to escape the % character rather
than doubling it:

xcopy c:\#$^%3fw.txt d:\
 
G

Guest

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.
 
P

Pegasus \(MVP\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top