Thanx a bunch - now get back to those taxes :-)
-----Original Message----- From: Diane Holt [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 11, 2002 11:20 AM To: Ant Users List Subject: Re: Deleting files that are X days old --- Mike Lecza <[EMAIL PROTECTED]> wrote: > Is there a way in Ant to delete files/folders that are older than X > days? (Anything to avoid doing my taxes :) <target name="springCleaning"> <fileset dir="." id="chkfiles"> <include name="*.log"/> </fileset> <pathconvert pathsep="," property="chkfiles" refid="chkfiles"/> <tstamp> <format property="cutoff" offset="-10" unit="day" pattern="MM/dd/yyyy HH:MM a"/> </tstamp> <script language="javascript"> <![CDATA[ importClass(java.io.File); importClass(java.text.DateFormat); importClass(java.util.Locale); importClass(java.util.StringTokenizer); var cutOff = projname.getProperty("cutoff"); var df = new DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, Locale.US); var parsedCutoff = df.parse(cutOff).getTime(); var files = projname.getProperty("chkfiles"); var st = new StringTokenizer(files, " ,"); while (st.hasMoreTokens()) { var file = new File(st.nextToken()); var modTime = file.lastModified(); if( parsedCutoff > modTime ) { showit = projname.createTask("echo"); showit.setMessage( "Deleting old file: " + file ); showit.execute(); } } ]]> </script> </target> Of course, you'd replace the "showit"s with delete's. Diane ===== ([EMAIL PROTECTED]) __________________________________________________ Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax http://taxes.yahoo.com/ -- 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]>
