This question already has an answer here:
- Nested batch for loops 4 answers
I want to execute some for loops for every path provided in a variable. The echo !temp!
works just fine, however the for commands below it won't work:
@echo off
setlocal enabledelayedexpansion
set paths=(C:\test C:\test2)
for %%p in %paths% do (
set temp=%%p
echo !temp!
for /r !temp! %%f in (*.h) do (echo %%f)
for /r !temp! %%g in (*.h *.cpp) do (echo %%g)
)
In all
for
commands syntax patterns:all text preceding
%%parameter
should be known in the first parsing phase. Read How does the Windows Command Interpreter (CMD.EXE) parse scripts?.However, next script should work as expected