Windows Batch script - what does %%i mean?

44,874

Solution 1

%%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:

Solution 2

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

Share:
44,874
snap171
Author by

snap171

Updated on May 05, 2020

Comments

  • snap171
    snap171 almost 4 years

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