Iterating over libraries and execute task in Ant
I need to be able to execute a task for all sub-directories with a certain name in Ant. For each sub-dir, I need to do an exec task
How can I do this ? Examples I found use fileset for copy tasks, which I can't use with the exec task, or开发者_运维问答 use a for loop which I can't get to work.
I also tried some Javascript, but I can't get the FSO to work at all.
You can do this with the Ant apply
task.
The task iterates over the members of a fileset-like object,
and it can process a dirset
too.
Here's an example:
<!-- all directories directly under working dir -->
<dirset id="my.dirs" dir="." includes="*" />
<apply executable="ls">
<arg value="-l" />
<dirset refid="my.dirs" />
</apply>
Apply has similar attibutes as the one-shot exec
task.
Did you try something like this (you need the antcontrib for task):
<for param="file">
<path>
<fileset dir="${yourdirectory}"/>
</path>
<sequential>
<!-- do the work you need to here -->
<echo>Filename === @{file}
</sequential>
</for>
This reference taken from here.
精彩评论