Finding and using the latest modified FOLDER/Direc

2019-04-11 01:09发布

So the current solution I have finds the latest modified FILE inside all of the folders. I need a way to get the latest modified folder. The reason being, a folder will get created on a daily basis, and I will need to use that folder value in a file path so that I can copy the contents of that path in another directory.

The code I have is as follows:

<target name = "latest">
 <copy todir = "H:\New">
  <last>
   <sort>
    <date xmlns="antlib:org.apache.tools.ant.types.resources.comparators"/>
    <filseset dir ="H:\test"/>
   </sort>
  </last>
 </copy>
</target>

Folder Overview
Main
|---Folder2(16/01/15)
|---Folder1(28/01/15)

The program needs to select Folder1 (overall idea).

I.E. of file path: C:/A/${latest.modified<}/etc/files

1条回答
一纸荒年 Trace。
2楼-- · 2019-04-11 01:50

To find a directory rather than a file, use a <dirset> instead of a <fileset>, for example:

<last id="last.dir">
    <sort>
        <dirset dir="H:\test" includes="*" />
        <date />
    </sort>
</last>
<echo message="${ant.refid:last.dir}" />
查看更多
登录 后发表回答