aspose file tools*
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 JavaScript Promises Essentials this week in the JavaScript 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
Author

Recursively iterate folders with Ant

ah bo
Greenhorn

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:

C:\Umbrella_Folder\ABC\file1
C:\Umbrella_Folder\ABC\file2
C:\Umbrella_Folder\DEF\file3
C:\Umbrella_Folder\DEF\file4

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

Joined: Jun 25, 2001
Posts: 16222
    
  21

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


Customer surveys are for companies who didn't pay proper attention to begin with.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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
drifter
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
Greenhorn

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
c:\apache-ant-1.8.2\bin\ant
cd ..

C:\Users\conor2\Desktop\JAVANE~1\NEURAL~1>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Recursively iterate folders with Ant