facewindu
facewindu

Reputation: 715

Ant check if a directory (and sub directories) contains a certain file

I'm trying to check in Ant if a directory (and sub directories) contains a certain file

I'm using ant contrib with :

<if>
  <available>
    <filepath>
      <fileset dir="myDir">
        <include name="**/*.AEF" />
      </fileset>
    </filepath>
  </available>
<then>
  <fail/>
</then>
</if>

I want to fail if there is at least a file ending with "AEF" in myDir or one of its sub-directories. But this fails even if no "*.AEF" file is found

Upvotes: 0

Views: 1563

Answers (1)

Nicolas Lalev&#233;e
Nicolas Lalev&#233;e

Reputation: 2013

This should do the job, without the need of ant-contrib:

<fail message="At least one .AEF file was found">
  <condition>
    <resourcecount when="greater" count="0">
      <fileset dir="myDir" includes="**/*.AEF" />
    </resourcecount>
  </condition>
</fail>

Upvotes: 7

Related Questions