?
Solved

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

Posted on 2005-04-04
5
Medium Priority
?
2,134 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:mbmart
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Accepted Solution

by:
brianadkins earned 750 total points
ID: 13703783

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
 
LVL 8

Expert Comment

by:ViRoy
ID: 13711897


or you could simply do this:

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

cd\directory2
ant

cd\directory3
ant
exit
-------------- end batch ---------------
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 13714501
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
 
LVL 16

Expert Comment

by:OliWarner
ID: 14317217
Just found this and found it immensely an immensely useful answer.

It wasnt my question but thank you experts.
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 14317223
^^ mostly to brianadkins for the explaination of for
Definately A-Grade matherial though
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question