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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:14:41  来源:igfitidea点击:

%%A was unexpected at this time

windowscommand-line

提问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

%%Ais 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 %ais sufficient. You only need to use %%afrom 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 /fswitch 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" 作为命令,这是/fswitch 与单引号结合的作用。完整的命令是:for %A in ("G:\Files Sample\zip\txt\*.txt") do 7za -tzip "%A.zip" "%A"

回答by Andreas Rohde

Try this in a batch file.

在批处理文件中试试这个。

FOR "G:\Files Sample\zip\txt\" %%G IN (*.txt) DO  7za -tzip "%%G.zip" "%%G"

Add /Ras option to search for the files in all subfolder.

添加/R为选项以搜索所有子文件夹中的文件。

A good explanation of cmd- methods you could find at ss64

您可以在ss64 上找到对 cmd- 方法的一个很好的解释