I have a script that recursively loads files from a specific directory (and subdirectories) into a java classpath using a FOR loop. It looks like this:
FOR /r directory %%F IN (*.jar) DO call :addcp %%F
Unfortunately, I need to now exclude a specific subdirectory from the results (I don't want some of the jar files loaded). I have tried nesting an IF statement inside of the FOR loop, but have not had any success.
Changing scripting languages is unfortunately not an option, and iterating out every subdirectory would be a maintenance nightmare. Does anyone have a way to do this?
I tried something like:
FOR /r directory %%F IN (*
.jar) DO IF %%F==*
string*
DO call :addcp %%F
but it didn't work.
Here's a script to dump a list of the absolute paths of all EXE files under "%ProgramFiles%" except those that are in the "Windows NT" subdirectory. I would think you could probably beat this into submission for what you're looking for.
I would recommend find, take a look at man find. Something like find "%ProgramFiles%\" -iname ".exe" ! -regex "%ProgramFiles%\folder_to-exclude.$" -exec call :addcp {} \; might do what you want.
%%F resolves to the path to the .jar file, not to the directory name, which is why the == doesn't work.
I suggest a 2-step process - first do
and then
the /V parameter to findstr prints all lines that don't match the string you pass in. You should be able to use wildcards or even regular expressions for your exclusion as well, if you really need to.