Recursive delete in ANT

D

dreamzzz

Is it possible to recursively delete all dirs and sub-dirs in a tree
structure?
I am trying to use the Fileset and delete all the directories along
with their contents. But it just deletes the contents of the dirs at
the lowest level and not the entire Dir structure.
 
T

Tony Morris

dreamzzz said:
Is it possible to recursively delete all dirs and sub-dirs in a tree
structure?
I am trying to use the Fileset and delete all the directories along
with their contents. But it just deletes the contents of the dirs at
the lowest level and not the entire Dir structure.

<delete dir="thedirectory"/>

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 
D

dreamzzz

Tony Morris said:
<delete dir="thedirectory"/>

I tried the above technique. But it doesnt solve my problem.
Actually I have a dir tree and i need to delete specific dirs in that
dir. These dirs can have sub or sub-sub dirs. Thats why i am using
fileset with Includes clause. But this just removes the contents at
the lowest level and not the entire dir structure specified.
 
T

Tony Morris

I tried the above technique. But it doesnt solve my problem.
Actually I have a dir tree and i need to delete specific dirs in that
dir. These dirs can have sub or sub-sub dirs. Thats why i am using
fileset with Includes clause. But this just removes the contents at
the lowest level and not the entire dir structure specified.

I am unsure of your intention.

<delete dir="thedir"/>
will delete "thedir" including any files and subdirectories within "thedir".

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 
O

Oscar kind

dreamzzz said:
I tried the above technique. But it doesnt solve my problem.
Actually I have a dir tree and i need to delete specific dirs in that
dir. These dirs can have sub or sub-sub dirs. Thats why i am using
fileset with Includes clause. But this just removes the contents at
the lowest level and not the entire dir structure specified.

You may want to look at dirset. It does the same as a fileset, but with
directories. IIRC, it also works with the delete task.


kind regards,
Oscar
 
Joined
Jul 29, 2008
Messages
1
Reaction score
0
delete works better than you think ...

Well, it's been 4 years since dreamzzz posted their question, but being I just ran into this (after forgetting about how Ant works from years ago), and being this page got a top hit from Google, I thought I'd post something relevant:

A typical delete might be to recursively delete all files in a tree - *including* the directories - but leave files of certain patterns. Something like:

<delete>
<fileset dir="${wrk.buildFilePath.dir}">
<include name="**"/>
<exclude name="**/projlib-build.xml"/>
<exclude name="**/*-projlib.zip"/>
</fileset>
</delete>


At first look, it seems to delete only those files in the base directory, but it leaves all the directories in place, so you might think it doesn't delete files recursively, but it does! A closer examination reveals that it's being quite literal, deleting only files. To get the intended behavior, simply request that emptry directories are deleted (not true by default):

<delete includeemptydirs="true">
...


Sure enough, the files to be excluded from delete remain, including their supporting directories. Everything else is deleted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top