user1390517
user1390517

Reputation: 249

how to check if a particular file is present in a directory or not

I have a jar file in /programs/src i want my program to print a message that it is present in the directory:

<if>
    <available file="**/*.jar" />
    <then>
        <echo message="Available" />
    </then>
    <else>
    <echo message="Not Available" />
    </else> 

but it is not working

Upvotes: 0

Views: 112

Answers (2)

Rebse
Rebse

Reputation: 10377

You may use the builtin ${toString:yourfilesetid} mechanism from ant combined with
Ant Addon Flaka like that :

<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">
 <fileset dir="/home/rosebud/temp" includes="**/*.jar" id="foobar"/>
  <fl:choose>
   <fl:when test=" '${toString:foobar}' ne '' ">
    <echo message="Available" />
    <!-- .. other stuff -->
   </fl:when>
   <fl:otherwise>
    <echo message="Not Available" />
    <!-- .. other stuff -->
   </fl:otherwise>
  </fl:choose>
</project>

Upvotes: 0

skaffman
skaffman

Reputation: 403611

There's nothing in the documentation for <available> that says it can handle wildcards. You need to use an actual file path.

Upvotes: 1

Related Questions