I have a variable %folder%
which contains one or more directories like so c:\users,c:\windows,d:\
etc. I need to do a dir
command into every directory in a way that allows multiple search terms found in %wildcards%
variable like *.txt *.lst "*old*news*"
etc. Here is my attempt
for /f "tokens=1,2,3,4,5,6,7,8,9,* delims=," %%a in ("%folders%") do (
if not "%%~a"=="" dir %%~a\%wildcards% /s /b /a-d 2>nul >%files%
if not "%%~b"=="" dir %%~b\%wildcards% /s /b /a-d 2>nul >>%files%
if not "%%~c"=="" dir %%~c\%wildcards% /s /b /a-d 2>nul >>%files%
if not "%%~d"=="" dir %%~d\%wildcards% /s /b /a-d 2>nul >>%files%
if not "%%~e"=="" dir %%~e\%wildcards% /s /b /a-d 2>nul >>%files%
if not "%%~f"=="" dir %%~f\%wildcards% /s /b /a-d 2>nul >>%files%
if not "%%~g"=="" dir %%~g\%wildcards% /s /b /a-d 2>nul >>%files%
if not "%%~h"=="" dir %%~h\%wildcards% /s /b /a-d 2>nul >>%files%
if not "%%~i"=="" dir %%~i\%wildcards% /s /b /a-d 2>nul >>%files%
if not "%%~j"=="" dir %%~j\%wildcards% /s /b /a-d 2>nul >>%files%
)
It fails with multiple wildcards. I guess this would work if I entered each directory so that no directory is required with the dir
commands, but the whole thing is already getting so convoluted I must be missing a simpler way of doing this?
[edit removed]