Today I wanted to find out, using Ant, if any of a set of files existed. Based on that information, I would conditionally execute a target. Well, really I needed to solve a problem in Maven, but an Ant solution would plug in just fine. Here’s what I came up with:
<project name="test" default="test" basedir=".">
<target name="test">
<delete file="target\dir\status.file"/>
<copy todir="target\dir">
<fileset dir="target\dir" includes="*.xml"/>
<mapper type="merge" to="status.file"/>
</copy>
<available property="test.any" value="true" file="target\dir\status.file"/>
<property name="test.any" value="false"/>
<echo>any.xml: ${test.any}</echo>
</target>
</project>
That seems to work. The side effect is that one file is duplicated exactly, but only one.

