Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@apache.org Received: (qmail 11500 invoked from network); 12 Oct 2002 00:27:34 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 12 Oct 2002 00:27:34 -0000 Received: (qmail 25415 invoked by uid 97); 12 Oct 2002 00:28:20 -0000 Delivered-To: qmlist-jakarta-archive-ant-user@jakarta.apache.org Received: (qmail 25374 invoked by uid 97); 12 Oct 2002 00:28:19 -0000 Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 25362 invoked by uid 98); 12 Oct 2002 00:28:18 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-Id: <5.1.0.14.0.20021011171118.047b8e90@orson.callenish.com> Date: Fri, 11 Oct 2002 17:27:27 -0700 To: "Ant Users List" From: Bruce Atherton Subject: RE: Delete all but the most recent N files In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N At 04:50 PM 10/9/2002 -0500, Dominique Devienne wrote: >You could achieve *almost* what you want I think using the 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 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: For additional commands, e-mail: