忽略批处理文件中的百分号 [英] Ignore percent sign in batch file
问题描述
我需要移动的某些文件中包含字符串%20:
move / y\\myserver\myfolder\file%20name.txt\\myserver\otherfolder
尝试找到一个名称为
的文件失败
\\myserver\myfolder\file0name.txt
有没有办法忽略%
?我无法更改生成的文件来避免这种情况,例如将符号百分比加倍( %%
),使用 /
或 ^
(插入符号)等。
你应该可以使用插入符号(^)以逃避百分号。
原因%2
正在消失的是,批处理文件替换了传入的第二个参数,而您似乎没有第二个参数。解决这个问题的一种方法是实际尝试 foo.bat ^%1 ^%2 ...
,以便当%2
在命令中遇到,它实际上用文字%2
替换。
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 "\\myserver\myfolder\file%20name.txt" "\\myserver\otherfolder"
This fails as it tries to find a file with the name:
\\myserver\myfolder\file0name.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.
You should be able to use a caret (^) to escape a percent sign.
The reason %2
is disappearing is that the batch file is substituting the second argument passed in, and your seem to not have a second argument. One way to work around that would be to actually try foo.bat ^%1 ^%2...
so that when a %2
is encountered in a command, it is actually substituted with a literal %2
.
这篇关于忽略批处理文件中的百分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!