Ant:如何从目录中选择最新的修改文件?

Pet*_*ter 12 ant

假设我有一个目录,其中包含几个具有相同名称前缀和时间戳的文件,例如

my-directory:
- file-0749
- file-1253
- file-2304
Run Code Online (Sandbox Code Playgroud)

如何告诉ANT从我的目录中选择最新修改的文​​件(在这种情况下,这将是文件-2304)?

les*_*ana 17

您可以使用ant-contrib中TimestampSelector任务执行此操作.

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

<echo message="${latest.modified}" />
Run Code Online (Sandbox Code Playgroud)