Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete a dirset of directories with Ant?

Tags:

java

build

ant

I want to delete all directories and subdirectories under a root directory that are contain "tmp" in their names. This should include any .svn files too. My first guess is to use

<delete>
    <dirset dir="${root}">
          <include name="**/*tmp*" />
    </dirset>
</delete>

This does not seem to work as you can't nest a dirset in a delete tag.

Is this a correct approach, or should I be doing something else?

  • ant version == 1.6.5.
  • java version == 1.6.0_04
like image 506
jamesh Avatar asked Oct 01 '08 17:10

jamesh


2 Answers

Here's the answer that worked for me:

<delete includeemptydirs="true">
    <fileset dir="${root}" defaultexcludes="false">
       <include name="**/*tmp*/**" />
    </fileset>
</delete>

I had an added complication I needed to remove .svn directories too. With defaultexcludes, .* files were being excluded, and so the empty directories weren't really empty, and so weren't getting removed.

The attribute includeemptydirs (thanks, flicken, XL-Plüschhase) enables the trailing ** wildcard to match the an empty string.

like image 164
jamesh Avatar answered Sep 17 '22 16:09

jamesh


try:

<delete includeemptydirs="true">
    <fileset dir="${root}">
          <include name="**/*tmp*/*" />
    </fileset>
</delete>

ThankYou flicken !

like image 44
Blauohr Avatar answered Sep 20 '22 16:09

Blauohr