如何使用ANT选择目录中的最后一个文件? 我有一个单独的脚本,它使用(DD-MM-YYYY)格式每天在同一时间将文件保存到目录中。
我想自动选择最新的文件(按名称或上次修改的日期)。 我有一个类似于此的文件结构。
Data
├── 20-08-2017.txt
├── 21-08-2017.txt
├── 22-08-2017.txt
我目前正在使用它来手动选择(和复制)文件:
<project name="CopyDemo" default="CopyDemo">
<target name="CopyDemo">
<copy file="22-08-2017.txt" tofile="file-COPY.txt"/>
</target>
</project>
答案 0 :(得分:1)
您可以按日期将last
与sort
结合使用,如下所示:
<project default="test" name="test">
<property name="source.directory" value="C:/Users/apps/Data" />
<target name="test">
<copy tofile="file-COPY.txt">
<last id="lastFile">
<sort>
<date/>
<fileset dir="${source.directory}"/>
</sort>
</last>
</copy>
<echo message="copied file :${ant.refid:lastFile}"/>
</target>
</project>