windows %%A 此时出乎意料
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9311562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
%%A was unexpected at this time
提问by klijo
I want to zip a folder containing files. So inorder to do that i need to loop through the entire file list and execute 7za command. (7zip command line version)
我想压缩一个包含文件的文件夹。所以为了做到这一点,我需要遍历整个文件列表并执行 7za 命令。(7zip 命令行版)
for /f %%A in ('"G:\Files Sample\zip\txt\*.t
xt"') do 7za -tzip "%%A.zip" "%%A"
However windows says that this command is not valid.
但是 windows 说这个命令无效。
Error message is
错误信息是
%%A was unexpected at this time
How do i overcome this issue ?
我如何克服这个问题?
回答by Royi Namir
%%A
is used when you use a batch program (*.bat)
%%A
使用批处理程序时使用 (*.bat)
try remove one '%'
尝试删除一个 '%'
回答by aross
If you are doing it from the command line, you don't have to escape the %, so %a
is sufficient. You only need to use %%a
from batch files.
如果您是从命令行执行此操作,则不必转义 %,这样%a
就足够了。您只需%%a
要从批处理文件中使用。
Also, you wanna be selecting the files instead of executing "G:\Files Sample\zip\txt\*.txt" as a command, which is what the /f
switch does in combination with single quotes. The full command would be: for %A in ("G:\Files Sample\zip\txt\*.txt") do 7za -tzip "%A.zip" "%A"
此外,您希望选择文件而不是执行 "G:\Files Sample\zip\txt\*.txt" 作为命令,这是/f
switch 与单引号结合的作用。完整的命令是:for %A in ("G:\Files Sample\zip\txt\*.txt") do 7za -tzip "%A.zip" "%A"