joeslomp
asked on
Complex DOs in a batch file
FOR /F "usebackq delims==" %%i IN (`type regions.txt`) DO @echo %%i
Hello.
I use the above example in a batch file to get one region at a time. My problem is that what I need to do for each region is quite complex, more than one line. One option would be to put all in another batch file, and use
FOR /F "usebackq delims==" %%i IN (`type regions.txt`) DO CALL otherstuff.bat %%i
but I would prefer to keep all in one batch file. Is this possible?
Thanks,
Joe
Hello.
I use the above example in a batch file to get one region at a time. My problem is that what I need to do for each region is quite complex, more than one line. One option would be to put all in another batch file, and use
FOR /F "usebackq delims==" %%i IN (`type regions.txt`) DO CALL otherstuff.bat %%i
but I would prefer to keep all in one batch file. Is this possible?
Thanks,
Joe
ASKER
Thanks, leew.
The file only contains region names (one word for each region). In fact I would like to not even use a file, and use the region name strings in my FOR command.
My DO actions are a sequence of other calls to many (20) other batch files, each batch file does something different with the region name.
The file only contains region names (one word for each region). In fact I would like to not even use a file, and use the region name strings in my FOR command.
My DO actions are a sequence of other calls to many (20) other batch files, each batch file does something different with the region name.
Post a couple. let me work out how a couple would work with things.
ASKER
For example
::joesbatchfile
set scriptsDir=%~dp0
REM this is a simple echo, but I would like to START all programs below for all regions
REM in the FOR loop
FOR /F "delims==" %%i IN (regions.txt) DO @echo %%i
REM
REM programs I need to start for each region
START "program 1" /W %scriptsDir%build01.bat
START "program 2" /W %scriptsDir%build02.bat
..
.. lots more
::joesbatchfile
set scriptsDir=%~dp0
REM this is a simple echo, but I would like to START all programs below for all regions
REM in the FOR loop
FOR /F "delims==" %%i IN (regions.txt) DO @echo %%i
REM
REM programs I need to start for each region
START "program 1" /W %scriptsDir%build01.bat
START "program 2" /W %scriptsDir%build02.bat
..
.. lots more
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes! That simple, once you know it! Thanks a bunch, and have a good night!
ASKER
For completeness:
FOR /F "tokens=*" %%i IN (regions.txt) DO (
START "program 1" /W build01.bat %%i
START "program 2" /W build02.bat %%i
)
Of course, buil0n.bat need an exit line, to return control to the master batch.
Cheers,
Joe
FOR /F "tokens=*" %%i IN (regions.txt) DO (
START "program 1" /W build01.bat %%i
START "program 2" /W build02.bat %%i
)
Of course, buil0n.bat need an exit line, to return control to the master batch.
Cheers,
Joe
One other note: You don't have to type the text file. You can simply reference it. For example:
FOR /F "delims==" %%i IN (regions.txt) DO @echo %%i