You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Andreas Held <an...@bbp.ch> on 2007/09/12 14:22:06 UTC
Deleting directories using restrict
Hi,
Using Ant 1.7.0, I am trying to delete some directories, based on a
comparison of their names:
<delete verbose="true">
<restrict>
<dirset dir="${dist_dir}" includes="*" />
<rsel:compare when="le" against="all">
<control>
<resource name="${delete-id}" />
</control>
<rcmp:name />
</rsel:compare>
<rsel:type type="dir" />
</restrict>
</delete>
This works well if and only if the directories in question are empty. If
they are not empty, the delete does not work. What am I doing wrong
here? Incidentally, the directory names are in the form of timestamps,
comparing using "le" should delete all that are older than a specified
timestamp. As there are other directories I have to keep, simply
deleting based on time does not work.
Any help is greatly appreciated.
Best regards,
Andreas
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Deleting directories using restrict
Posted by Andreas Held <an...@bbp.ch>.
Since nobody took this up, I will add some more information.
Looking into the Ant sources (V1.7.0, Delete.java) shows the following
snippet:
if (resourcesToDelete.isFilesystemOnly()) {
for (Iterator iter = resourcesToDelete.iterator(); iter.hasNext();) {
FileResource r = (FileResource) iter.next();
// nonexistent resources could only occur if we already
// deleted something from a fileset:
if (!r.isExists()) {
continue;
}
if (!(r.isDirectory()) || r.getFile().list().length == 0) {
log("Deleting " + r, verbosity);
if (!delete(r.getFile()) && failonerror) {
handle("Unable to delete "
+ (r.isDirectory() ? "directory " : "file ") + r);
}
}
}
} else {
This means, in the case of resource collections, directories are not
treated the same as in the case of setting "dir" directly. Is there a
deep reason behind this I don't understand?
Best regards
Andreas
> Hi,
>
> Using Ant 1.7.0, I am trying to delete some directories, based on a
> comparison of their names:
>
> <delete verbose="true">
> <restrict>
> <dirset dir="${dist_dir}" includes="*" />
> <rsel:compare when="le" against="all">
> <control>
> <resource name="${delete-id}" />
> </control>
> <rcmp:name />
> </rsel:compare>
> <rsel:type type="dir" />
> </restrict>
> </delete>
>
> This works well if and only if the directories in question are empty. If
> they are not empty, the delete does not work. What am I doing wrong
> here? Incidentally, the directory names are in the form of timestamps,
> comparing using "le" should delete all that are older than a specified
> timestamp. As there are other directories I have to keep, simply
> deleting based on time does not work.
>
> Any help is greatly appreciated.
>
> Best regards,
>
> Andreas
>
>
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org