Nested Directory Searching in Batch File -



Nested Directory Searching in Batch File -

i trying run recursive loop on few directories. works:

for /r "dir1" %%f in (*.c *.cpp *.h) ( echo %%f ) /r "dir2" %%f in (*.c *.cpp *.h) ( echo %%f )

but since silly (the echo part block of commands, , number of directories large), tried this:

for %%d in (dir1 dir2) ( /r "%%d" %%f in (*.c *.cpp *.h) ( echo %%f ) )

which didn't work (it didn't run anything). there way work?

for reason for /r doesn't late-expansion variables search path. ran procmon , found cmd.exe attempting access file/directory named %d!

one documented feature of /r if leave out directory, search cwd. used come altered form of script appears function.

for %%d in (dir1 dir2) ( pushd "%%~d" /r %%f in (*.c *.cpp *.h) ( echo %%f ) popd )

fwiw, sake of script maintainability, if there more few dirs, rather list them in command, set directories search in separate text file , utilize for /f iterate on them. perhaps wrote provide minimal working example.

batch-file

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -