Reputation: 189686
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?
Upvotes: 0
Views: 174
Reputation: 34148
You need to use delayed expansion, you add SETLOCAL ENABLEDELAYEDEXPANSION to the top your batch file, and use ! rather than % around the variable names.
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
set TMPCLASSPATH=
for %%j IN (*.jar) DO set TMPCLASSPATH=!TMPCLASSPATH!;%%j
echo %TMPCLASSPATH%
Upvotes: 2