Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

escaping - Ignore percent sign in batch file

I have a batch file which moves files from one folder to another. The batch file is generated by another process.

Some of the files I need to move have the string "%20" in them:

move /y "\myservermyfolderfile%20name.txt" "\myserverotherfolder"

This fails as it tries to find a file with the name:

\myservermyfolderfile0name.txt

Is there any way to ignore %? I'm not able to alter the file generated to escape this, such as by doubling percent signs (%%), escaping with / or ^ (caret), etc.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to use %% in this case. Normally using a ^ (caret) would work, but for % signs you need to double up.

In the case of %%1 or %%i or echo.%%~dp1, because % indicates input either from a command or from a variable (when surrounded with %; %variable%)

To achieve what you need:

move /y "\myservermyfolderfile%%20name.txt" "\myserverotherfolder"

I hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...