Alex Rivera | Logout

Ant: How to select the latest modified file from a directory?

Asked 2011-03-31T10:55:02.750
12

Assume I have a directory which contains several files with the same name prefix and a timestamp, e.g.

my-directory:
- file-0749
- file-1253
- file-2304

How can I tell ANT to select the latest modified file from my directory (in this case this would be file-2304)?

ant
Edit
Report

1 Answer

18

You can do that with the TimestampSelector task from ant-contrib.

<timestampselector property="latest.modified">
  <path>
    <fileset dir="${my-directory.dir}">
      <include name="file-*" />
    </fileset>
  </path>
</timestampselector>

<echo message="${latest.modified}" />
answered 2011-03-31T13:11:52.350

Your Answer