Ant Recursive Delete


Ever wonder how to recursively delete Files AND Folders matching a given name with-in an Ant task ??

After reading delete task doc here is my (the ??) default first attempt for deleting recursively Files AND Folders which name contains “org.junit” from the src directory:


<delete verbose="true" includeemptydirs="true">
  <fileset dir="src" includes="**/org.junit*" />
</delete>

This will only deletes Files containing “org.junit” but not folders !!!

The solution to also delete folders :


<delete verbose="true" includeemptydirs="true">
  <fileset dir="src" includes="**/org.junit*/**" />
</delete>

The only difference is in the includes value where */** was added at the end of the “path”.

Hope this tip will avoid others to waste half an hour to do this ;)

Advertisements

4 thoughts on “Ant Recursive Delete

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s