How do I iterate over a set of folders in Windows Shell?

cmd, scripting, shell, windows

Solution

This works for me:

echo %ROOT%
for /D %%f in (%ROOT%\Binaries\*) do echo %%f && if not exist %%f\Subfolder md %%f\Subfolder

Problem

I'm currently trying to write a .cmd Windows Shell script that would iterate over a set of folders. However even the following simplest script: ``` echo "%ROOT%" for %%f in ("%ROOT%\Binaries\" ) do ( echo "%%f" if not exist "%%f\Subfolder" md "%%f\Subfolder" ) ``` outputs: ``` CurrentDir>echo "<ActualPathToRoot>" "<ActualPathToRoot>" %f\Subfolder was unexpected at this time CurrentDir>if exists "%f\Subfolder" ``` What am I doing wrong? How do I alter that script so that it iterates over that one folder and once it see there's no subfolder named "Subfolder" it creates that subfolder? Also is there a good tutorial on writing such scripts?

Original source