Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding and using the latest modified FOLDER/Directory using ant

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

like image 612
VedhaR Avatar asked Nov 17 '25 19:11

VedhaR


1 Answers

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}" />
like image 200
martin clayton Avatar answered Nov 19 '25 09:11

martin clayton