views:

28

answers:

1

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?

+2  A: 

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%
John Knoeller
works like a charm! Thanks! :-)
Jason S