ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Atherton <br...@callenish.com>
Subject RE: Delete all but the most recent N files
Date Sat, 12 Oct 2002 00:27:27 GMT
At 04:50 PM 10/9/2002 -0500, Dominique Devienne wrote:
>You could achieve *almost* what you want I think using the <date> selector,
>but it only takes an absolute date instead of a relative one. Writing a
>different selector that takes a relative date should be easy.
>
>Doing exactly what you want with a selector seems impossible, since
>selectors need to decide for every single file whether to include it or not,
>and in your case you need to know the most N recent files to include only
>those (you would need *global* selectors, or two passes...).
>
>It's a shame I think, because writing a custom task for this specific job is
>fine, but as a selector, it can be used with any task that takes a fileset,
>which makes it much more powerful. --DD
>
>-----Original Message-----
>From: Richard Dallaway [mailto:richard@dallaway.com]
>Sent: Wednesday, October 09, 2002 4:06 PM
>To: Ant Users List
>Subject: Delete all but the most recent N files
>
>I'm looking for a task that will allow me to delete a set of files,
>except for the last N (say, the last 5 most recently modified files).


I think that you could probably do what is being requested with a custom 
mapper and the <depend> selector. Make the mapper act like a merge mapper, 
but have the "to" attribute automatically filled in with the 5th most 
recent file. If you wanted to generalize things so that the mapper could be 
useful to more people, you could have a "sortfield" attribute (date, size, 
name) and "count" attribute that could select any element from the list 
(using negative numbers to go from the end back). You'd probably also want 
to make sure you cached the mapper's "to" attribute setting so it wasn't 
recreating the list and counting down for every file that was checked.

I have exactly the same problem with backed up build directories and log 
files that periodically need to be cleaned out manually, so I'd personally 
find this useful. It feels like it is getting a little scripty, though.



--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message