ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject Re: Deleting files that are X days old
Date Thu, 11 Apr 2002 15:20:14 GMT
--- 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>


Mime
View raw message