Clever indeed, if not wicked ;-) I can see how it would work. <mapper> are powerful, but always get me confused though. Some kind of 'global' selectors, or fileset-filters would be useful though in such situations. Thanks for the idea. --DD
-----Original Message----- From: Bruce Atherton [mailto:[EMAIL PROTECTED]] Sent: Friday, October 11, 2002 7:27 PM To: Ant Users List Subject: RE: Delete all but the most recent N files 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:[EMAIL PROTECTED]] >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:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>