아래에 있는 폴더처럼 'PluginA', 'PluginB' 아래에 있는 모든 모듈을 가져오고 싶으면 2중 loop 를 돌아야하는데 윈도우 배치 파일 for 에서는 바로 중첩을 사용할 수 없다.
< 폴더 구조 >
Plugins/PluginA/Source/ModuleA1
/ModuleA2
/ModuleA3
Plugins/PluginB/Source/ModuleB1
/ModuleB2
python 이나 powershell 로 하면 쉽겠지만 윈도우 배치 파일로만 처리해야한다면 for 와 call 을 이용하여 처리할 수 있다.
for /f %%a ('dir /ad /b Plugins') do call :process_sub Plugins\%%a
goto :eof:process_sub
for /f %%b ('dir /ad /b %1\Source') do echo %1\Source\%%b
goto :eof
label 을 이용해서 subroutine 을 만든다. 그리고 call 을 이용해서 호출하고 'goto :eof' 나 'exit /b' 이용하여 리턴하면 된다.
출처 :
728x90