忽略批处理文件中的百分号 [英] Ignore percent sign in batch file

查看:124
本文介绍了忽略批处理文件中的百分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件将文件从一个文件夹移动到另一个文件夹。批处理文件由另一个进程生成。



我需要移动的某些文件中包含字符串%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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆