jeudi 4 mars 2010

How to check if a folder is empty using ANT

The following build will fail in case where the c:/test folder is empty.
Note: Requiers ANT 1.7+

    <target name="isdirEmpty">
      <fileset id="fileset.test" dir="c:/test">
        <include name="*.*"/>
      </fileset>
     <fail message="File not found"> 
      <condition>
           <resourcecount refid="fileset.test" 
                             when="less" 
                             count="1"  >
        </resourcecount>
      </condition>
     </fail>
    </target>

Aucun commentaire: