FinalFive
FinalFive

Reputation: 1485

Using Ant to delete a file based on existence of another file

I need to write an ant task to selectively delete files.

In a directory, I have the following jars:

acme.jar acme-201105251330.jar

I want to delete acme.jar because acme-*.jar exists.

Here's what I've tried:

<target name="-check-use-file">
<available property="file.exists"> 
<filepath> <fileset dir="."> 
  <include name="./test-*.jar"/> </fileset> 
</filepath> 
</available> 
</target> 
<target name="use-file" depends="-check-use-file" if="file.exists"> 
<!-- do something requiring that file... --> 
</target>

Thanks

Upvotes: 1

Views: 330

Answers (1)

mindas
mindas

Reputation: 26713

Have a look at If/Unless Attributes, examples given there seem to be exactly what you are looking for.

Upvotes: 1

Related Questions