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
joeslompAsked:
Who is Participating?
 
Lee W, MVPConnect With a Mentor Technology and Business Process AdvisorCommented:
I'm sorry, it's VERY late for me... maybe this will make more sense to me after I sleep....

Right now all I see is you echoing the region.  This makes no sense to me (right now).

the way I work, it would really help if you could post a couple of sample lines from REGIONS.TXT

As I think about it, if the REGIONS.TXT only contains one word for each region, then you don't need the delims parameter.  This should work:

FOR /F "tokens=*" %%i IN (regions.txt) DO @echo %%i

(Sorry, I know this isn't the question, but I like to see things optimized where I can...

Maybe you mean this?

FOR /F "tokens=*" %%i IN (regions.txt) DO (
   START "program 1" /W %scriptsDir%build01.bat
   START "program 2" /W %scriptsDir%build02.bat
)
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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

0
 
joeslompAuthor Commented:
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.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Post a couple.  let me work out how a couple would work with things.
0
 
joeslompAuthor Commented:
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
0
 
joeslompAuthor Commented:
Yes! That simple, once you know it! Thanks a bunch, and have a good night!
0
 
joeslompAuthor Commented:
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
0
All Courses

From novice to tech pro — start learning today.