Create batch file to loop through directories and run a program in each directory

I want to create an MS-DOS batch file that will loop through several directories then run the "ant" program in each of those directories.

Thank you for your help in advance.
mbmartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brianadkinsCommented:

to list all folders and subfolders:

dir /ad /s /b

to loop through all of these folders and run a specific program:

for /f "delims=" %%a in ('dir /ad /s /b') do (
cd /d "%%a"
ant.exe
)


Or, if 'ant' takes a command line argument for a directory:

for /f "delims=" %%a in ('dir /ad /s /b') do (
ant.exe "%%a"
)

or something like that (don't know what 'ant' is...)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ViRoyCommented:


or you could simply do this:

------------ start batch file ------------
cls
cd\directory1
ant

cd\directory2
ant

cd\directory3
ant
exit
-------------- end batch ---------------
0
[ fanpages ]IT Services ConsultantCommented:
You could also use the "sweep.com" or PC-Plus provided "everydir.exe" utility:

http://www.pcplus.co.uk/tips/default.asp?pagetypeid=2&articleid=5528&subsectionid=390

=============================================================================
EVERYDIR.EXE v1.0 (c) Ian Sharpe October 2000

Executes specified command line in every sub-folder.

Root folder defaults to current folder, or specify with /root:<folder path>
Eg:

   everydir c:\somepath\somecommand parameter1 parameter2
   everydir /root:C:\mydocu~1 c:\somepath\somecommand parameter1 parameter2

Note:
 1 '/root:' must be the first parameter or it will become a parameter to
   the target program
 2 Sorry, but no long filenames. Use short filenames only.
 3 For built-in DOS commands use everydir command /c <command>

============================================================================

BFN,

fp.
0
OliWarnerCommented:
Just found this and found it immensely an immensely useful answer.

It wasnt my question but thank you experts.
0
OliWarnerCommented:
^^ mostly to brianadkins for the explaination of for
Definately A-Grade matherial though
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.