The <available> command can help you to check if a file or folder exists. Unfortunately it doesn’t support wildcard checking. Here is an workaround using the <pathconvert> such that we can check if a file or folder exists with wildcard.
<pathconvert property="filePath" setonempty="false" pathsep=" ">
<path>
<fileset dir="./" includes="a_file_name_with_wildcard*" />
</path>
</pathconvert>
<condition property="fileExists">
<resourcecount when="greater" count="0">
<fileset file="${filePath}"/>
</resourcecount>
</condition>
<if>
<istrue value="${fileExists}"/>
<then>
<echo message="File exists"/>
</then>
<else>
<echo message="File NOT exists"/>
</else>
</if>
Please note that it only works if there is only one file matched the wildcard file name. This is because the <pathconvert> would returns more than one file path if there are more than one file. So it’s not a perfect solution but should be good enough for you to explore more from this example.
Done =)
Reference: StackOverflow – How to use wildcard in Ant’s Available command
