ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Lecza" <mle...@newnetco.com>
Subject RE: Deleting files that are X days old
Date Wed, 17 Apr 2002 18:45:22 GMT
This script works great but now I want to delete entire directories.  Is
there a wat to check the date on a subdirectory then delete the entire
thing if it is old?

Regards,
Mike


-----Original Message-----
From: Diane Holt [mailto:holtdl@yahoo.com] 
Sent: Thursday, April 11, 2002 11:20 AM
To: Ant Users List
Subject: Re: Deleting files that are X days old

--- Mike Lecza <mlecza@newnetco.com> 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

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

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


--
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