tags:

views:

91

answers:

1

I want to generate a classpath automatically with all the *.jar files contained under my lib folder.

I can't find a way to list all these files with their absolute path, so that I can build my classpath variable.

It seems the dir command do not allow to get the absolute path, even when you go recursively with a /s.

Basically what I had in mind was something like :

set classpath = ./conf
for %%i in (`dir /s /withaboslutepath *.jar`) do set classpath = %classpath%;"%%x"

Is there a way to achieve this ?

+1  A: 

I've created something like this:

setlocal EnableDelayedExpansion
set classpath=./conf
FOR /R . %%x IN (*.jar) do set classpath=!classpath!;"%%~px"
echo !classpath!
endlocal

The problem with this solution are the duplicated paths.

chalup
What do you mean by duplicates ? It seems to work ok.
subtenante
If you have two jar files in the same directory, this directory will be added twice to classpath variable.
chalup
Oh yeah... actually I need to specify the jar files themselves so I replaced your %%~px with only %%x. Thanks a lot !
subtenante