Ant: How to execute a command for each file in directory?

ivan_ivanovich_ivanoff picture ivan_ivanovich_ivanoff · Sep 23, 2009 · Viewed 129.5k times · Source

I want to execute a command from an Ant buildfile, for each file in a directory.
I am looking for a platform-independent solution.

How do I do this?

Sure, I could write a script in some scripting language, but this would add further dependencies to the project.

Answer

Alex picture Alex · Oct 26, 2010

Use the <apply> task.

It executes a command once for each file. Specify the files by means of filesets or any other resource. <apply> is built-in; no additional dependency needed; no custom task implementation needed.

It's also possible to run the command only once, appending all files as arguments in one go. Use the parallel attribute to switch the behaviour.

Sorry for being late a year.