使用 ANT 选择最新的文件
Selecting the newest file using ANT
我将如何使用 ANT select 目录中的最后一个文件?
我有一个单独的脚本,每天在同一时间以 (DD-MM-YYYY) 格式将文件保存到目录中。
而且我想 select 自动更新最新文件(按名称或上次修改日期。
我有一个类似于此的文件结构。
Data
├── 20-08-2017.txt
├── 21-08-2017.txt
├── 22-08-2017.txt
我目前正在使用它来 select(并手动复制)一个文件:
<project name="CopyDemo" default="CopyDemo">
<target name="CopyDemo">
<copy file="22-08-2017.txt" tofile="file-COPY.txt"/>
</target>
</project>
您可以按日期将 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>
我将如何使用 ANT select 目录中的最后一个文件? 我有一个单独的脚本,每天在同一时间以 (DD-MM-YYYY) 格式将文件保存到目录中。
而且我想 select 自动更新最新文件(按名称或上次修改日期。 我有一个类似于此的文件结构。
Data
├── 20-08-2017.txt
├── 21-08-2017.txt
├── 22-08-2017.txt
我目前正在使用它来 select(并手动复制)一个文件:
<project name="CopyDemo" default="CopyDemo">
<target name="CopyDemo">
<copy file="22-08-2017.txt" tofile="file-COPY.txt"/>
</target>
</project>
您可以按日期将 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>