6

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

John Smith
  • 7,243
  • 6
  • 49
  • 61
snap171
  • 61
  • 1
  • 1
  • 6

2 Answers2

10

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

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

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

npocmaka
  • 55,367
  • 18
  • 148
  • 187