Link to home
Start Free TrialLog in
Avatar of joeslomp
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
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

I think I need more info to help you.  Can you provide 2 or 3 sample lines from the text file and details about what you do with them?  Yes, EVERYTHING should be possibly from one batch file.

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

Avatar of joeslomp
joeslomp

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.
Post a couple.  let me work out how a couple would work with things.
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
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes! That simple, once you know it! Thanks a bunch, and have a good night!
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