Reputation: 20091
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?
Upvotes: 14
Views: 27846
Reputation: 368
I just wanted to add that the part of the solution that worked for me was appending /**
to the end of the include path. I tried the following to delete Eclipse .settings directories:
<delete includeemptydirs="true">
<fileset dir="${basedir}" includes"**/.settings">
</delete>
but it did not work until I changed it to the following:
<delete includeemptydirs="true">
<fileset dir="${basedir}" includes"**/.settings/**">
</delete>
For some reason appending /**
to the path deletes files in the matching directory, all files in all sub-directories, the sub-directories, and the matching directories. Appending /*
only deletes files in the matching directory but will not delete the matching directory.
Upvotes: 5
Reputation: 20091
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.
Upvotes: 23
Reputation: 6003
try:
<delete includeemptydirs="true">
<fileset dir="${root}">
<include name="**/*tmp*/*" />
</fileset>
</delete>
ThankYou flicken !
Upvotes: 5