ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <>
Subject RE: Alternative for <available> taks to check a pattern of file existence
Date Thu, 29 Oct 2009 12:24:14 GMT

-----Original Message-----
From: cvsusr [] 
Sent: Thursday, October 29, 2009 12:00 PM
Subject: Alternative for <available> taks to check a pattern of file existence


I need to check for existence of files with some extension say *.txt in a
folder and if present execute a target..

I found only <available> task which checks for the existence of single file
only when the name of the file known. I wanted to check whether *.txt is
present or not.. if present execute a target..

one possible solution, the extension you're are looking for is
part of the glob attribute =

your/path/**/*.yourextension means recursive
your/path/*.yourextension means non recursive

examplescript, look for files with .xml extension in C:/Temp
and set property with number of found files
the condition checks whether there are *.xml files in C:/Temp
 - means property set by scriptdef != 0
and then your targets use if / unless with condition property

<project name="bla" default="main" basedir=".">

  <scriptdef name="filecount" language="ruby">
    <attribute name="glob"/>
    <attribute name="property"/>
    $project.setProperty "#{$attributes.get('property')}",

  <target name="checkfiles">
    <filecount glob="C:/Temp/**/*.xml" property="xmlfiles"/>
    <condition property="files">
        <equals arg1="${xmlfiles}" arg2="0" />

  <target name="foo" if="files">
    <echo>${xmlfiles} files found ..</echo>

  <target name="foobar" unless="files">
    <echo>no files found ..</echo>

  <target name="main" depends="checkfiles,foo,foobar"/>

Regards, Gilbert
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message