Ignore percent sign in batch file

后端 未结 6 2383
北恋
北恋 2020-11-22 14:33

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 \"

6条回答
  •  温柔的废话
    2020-11-22 15:16

    You should be able to use a caret (^) to escape a percent sign.

    Editor's note: The link is dead now; either way: It is % itself that escapes %, but only in batch files, not at the command prompt; ^ never escapes %, but at the command prompt it can be used indirectly to prevent variable expansion, in unquoted strings only.

    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.

提交回复
热议问题