snap171
snap171

Reputation: 61

Windows Batch script - what does %%i mean?

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

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++?

Upvotes: 6

Views: 64735

Answers (2)

npocmaka
npocmaka

Reputation: 57272

In this case FOR /D iterates 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 %i in ("C:\commonfiles\*") do RD /S /Q "%i"

For more info FOR /? or SS64.COM

Upvotes: 1

David Heffernan
David Heffernan

Reputation: 613262

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

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

Upvotes: 10

Related Questions