Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
How can I capture a file 's date to a property?

How can I capture a file 's date to a property?

2007-07-12       - By Rebhan, Gilbert
Reply:     1     2     3     4     5     6     7     8     9     10  


Hi,

-----Original Message-----
From: cknell@(protected) [mailto:cknell@(protected)]
Sent: Wednesday, July 11, 2007 9:21 PM
To: user@(protected)
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"/>
  <![CDATA[
   attr = $bsf.lookupBean("attributes")
   fname = attr.get("fname")
   prop = attr.get("prop")
   t=File.atime(fname)
   $project.setNewProperty "filename", fname
    $project.setNewProperty prop, t.strftime("%m.%d.%Y")
  ]]>
  </scriptdef>

<filemod fname="y:/test.txt"
         prop="fmod"/>

 </target>

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

see other time formatting possibilities  http://www.ruby.ch/ProgrammingRuby
/htmlC/ref_c_time.html#strftime

or with javascript
<scriptdef name="filemod" language="javascript">
<attribute name="fname"/>
<attribute name="prop"/>
<![CDATA[
 fname = attributes.get("fname");
 prop = attributes.get("prop");
 f = new java.io.File(fname);
 date = new Date(f.lastModified());
 project.setNewProperty("filename", f);
 project.setNewProperty(prop, date);
]]>
</scriptdef>

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


Regards, Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.