Windows 批处理脚本 - %%i 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27289905/
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-08 18:51:53  来源:igfitidea点击:

Windows Batch script - what does %%i mean?

windowsbatch-filefor-loop

提问by snap171

I wrote (using knowledge from Internet) script (batch file) to remove all folders and files inside a folder.

我编写了(使用 Internet 上的知识)脚本(批处理文件)来删除文件夹中的所有文件夹和文件。

DEL /F /Q /S C:\commonfiles\*
for /D %%i in ("C:\commonfiles\*") do RD /S /Q "%%i"

I just don't know what %%i means. Is it like i++ in C++?

我只是不知道 %%i 是什么意思。它像 C++ 中的 i++ 吗?

回答by David Heffernan

%%iis simply the loop variable. This is explained in the documentation for the forcommand, which you can get by typing for /?at the command prompt.

%%i只是循环变量。这在for命令的文档中进行了解释,您可以通过for /?在命令提示符下键入来获取该文档。

The fact that a double percent sign is used in a batch file is discussed in these links:

这些链接中讨论了在批处理文件中使用双百分号的事实:

回答by npocmaka

In this case FOR /Diterates trough all directories in C:\commonfiles\and on each iteration the current directory is accessible with %%i variable. It's a special variable that is valid only in FOR command context. In command prompt you'll need to use:

在这种情况下,在每次迭代中FOR /D遍历所有目录,C:\commonfiles\当前目录可通过 %%i 变量访问。它是一个特殊变量,仅在 FOR 命令上下文中有效。在命令提示符下,您需要使用:

for /D %i in ("C:\commonfiles\*") do RD /S /Q "%i"

for /D %i in ("C:\commonfiles\*") do RD /S /Q "%i"

For more info FOR /?or SS64.COM

欲了解更多信息FOR /?SS64.COM