For example
/test/a.jar
/test/b.jar
/test/c.jar
output:
a.jar
b.jar
c.jar
This works for the most part, except it only seems to be getting one of the files, not all =/
<for param="file">
<path>
<fileset dir="${test.dir}/lib">
<include name="**/*.jar"/>
</fileset>
</path>
<sequential>
<basename property="filename" file="@{file}"/>
<echo message="${filename}"/>
</sequential>
</for>
This just gets me:
c.jar
c.jar
c.jar
The problem you've hit is the immutability of Ant properties - once a property is set the value cannot normally be changed.
The first time around the loop the filename
property is being set, and that value 'sticks'.
Since Ant 1.8 the local
task allows you to localise a property to the current execution block. For example, your sequential
would be:
<sequential>
<local name="filename" />
<basename property="filename" file="@{file}"/>
<echo message="${filename}"/>
</sequential>
Ant forgets the property at the end of the sequential, so a new value can be used in each iteration.
It's been a while since I've done anything with ant, but have you tried a foreach?
<foreach>
<fileset dir="${test.dir}/lib">
<include name="**/*.jar"/>
</fileset>
<echo message="${foreach.file}"/>
</foreach>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With