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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -