ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <>
Subject RE: How can I capture a file's date to a property?
Date Thu, 12 Jul 2007 09:01:58 GMT


-----Original Message-----
From: [] 
Sent: Wednesday, July 11, 2007 9:21 PM
Subject: How can I capture a file's date to a property?

I've have found several tasks for copying and renaming files and
directories, but no way to get the file's date-stamp.

i would go via <script> i.e.

with jruby =

<project name="bla" default="main" basedir=".">
  <target name="depends">
  <scriptdef name="filemod" language="ruby">
   <attribute name="fname"/>
   <attribute name="prop"/>
    attr = $bsf.lookupBean("attributes")
    fname = attr.get("fname")
    prop = attr.get("prop")
    $project.setNewProperty "filename", fname
     $project.setNewProperty prop, t.strftime("%m.%d.%Y")

 <filemod fname="y:/test.txt"

  <target name="main" depends="depends">
      ${filename} last modified => ${fmod}

see other time formatting possibilities =

or with javascript =

<scriptdef name="filemod" language="javascript">
 <attribute name="fname"/>
<attribute name="prop"/>
  fname = attributes.get("fname");
  prop = attributes.get("prop");
  f = new;
  date = new Date(f.lastModified());
  project.setNewProperty("filename", f);
  project.setNewProperty(prop, date);

have a look at java.util.Date apidocs if
you need other time formatting

Regards, Gilbert

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message