In my use of Ant, I have frequently had the need to delete a set of files
based on some wildcard specifications. To do this, I have written a new
task definition for "deletefiles". I have included the documentation
below. Would there be interest in this as an addition to the Ant standard
tasks? I'd be glad to contribute it.
<hr>
<h2><a name="deletefiles">Deletefiles</a></h2>
<h3>Description</h3>
<p>Deletes all files from the specified directory and its sub-directories.</p>
<p>It is possible to refine the set of files that are being deleted. This
can be
done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> attribute you specify the files you
want to
have included in the deletion process by using patterns. The <i>exclude</i>
attribute is used to specify
the files you want to have excluded from the deletion process. This is also
done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
href="#directorybasedtasks">directory based tasks</a>, on how the
inclusion/exclusion of files works, and how to write patterns. The patterns
are
relative to the <i>deldir</i> directory.</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">deldir</td>
<td valign="top">the directory to delete files from.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">includes</td>
<td valign="top">comma separated list of patterns of files that must be
deleted. All files are in the current directory
and any sub-directories are deleted when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded from the deletion list. No files (except default excludes)
are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
("yes"/"no"). Default excludes are used when
omitted.</td>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Examples</h3>
<pre> <deletefiles deldir="lib" /></pre>
<p>deletes all files in the <code>/lib</code> directory.</p>
<pre> <deletefiles deldir="."
include="**/*.bak"
/>
</pre>
<p>deletes all files with the extension "<code>.bak</code>" from
the current directory
and any sub-directories.</p>
<hr>
As an aside - is the set of default excludes defined anywhere other than
the source?? I'm presuming that the definition found in class
DirectoryScanner is it.
/**
* Patterns that should be excluded by default.
*
* @see #addDefaultExcludes()
*/
private final static String[] DEFAULTEXCLUDES = {
"**/*~",
"**/#*#",
"**/%*%",
"**/CVS",
"**/CVS/*",
"**/.cvsignore"
};
----------------------------------------------------------------------------
Tom Dimock ---- Cornell University ---- [EMAIL PROTECTED]
"There go my people. I must follow them, for I am their leader." M. Gandhi