Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-04-04
5
Medium Priority
?
2,165 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
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

580 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