This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Recursively iterate folders with Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Recursively iterate folders with Ant" Watch "Recursively iterate folders with Ant" New topic

Recursively iterate folders with Ant

ah bo

Joined: Aug 22, 2001
Posts: 9
I am wondering if this is possible to do in Ant. I want do produce a zip file for each directory that I encounter under an umbrella directory by going through all the folders under the umbrella folder recursively. e.g.

If I have the following structure:


With the above structure, I want to produce (which includes file1 and file2) and (which includes file3 and file4). Can this be done? Thanks a lot in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

Probably, if you use Ant+JavaScript. Ant alone isn't likely to be capable of that much programmability.

An IDE is no substitute for an Intelligent Developer.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
I wrote an article on scripting Ant builds a while back. That might be of interest to you.

Having said that, I believe "the Ant way" to do something like what you're describing would be to write a custom Ant task (in Java) instead of embedding code in a scripting language.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
You could try using the ant-contrib tasks.

We don't use them on a regular basic, but a while back I seem to recall trying it out and it did what I wanted. Then I decided I didn't really need it.
Conor Williams

Joined: Oct 31, 2012
Posts: 4
C:\Users\conor2\Desktop\JAVANE~1\NEURAL~1>type Mybuild.bat

for /d %%j in (C:\Users\conor2\Desktop\JAVANE~1\NEURAL~1\*.) do c:\users\cono
r2\desktop\javane~1\neural~1\mybuild2.bat %%j

C:\Users\conor2\Desktop\JAVANE~1\NEURAL~1>type mybuild2.bat
cd %1
cd ..

wood burning stoves
subject: Recursively iterate folders with Ant
It's not a secret anymore!