In a Windows batch file, I want to construct a classpath of .jar files in a trusted directory.
I thought this might work:
set TMPCLASSPATH=
for %%J in (*.jar) do set TMPCLASSPATH=%TMPCLASSPATH%;%%J
This doesn’t seem to work, since %TMPCLASSPATH% appears to be evaluated once at the beginning of the for loop.
Any suggestions?
You need to use delayed expansion, you add SETLOCAL ENABLEDELAYEDEXPANSION to the top your batch file, and use ! rather than % around the variable names.