Forum Discussion

Alina's avatar
Alina
Occasional Contributor
12 years ago

Return Folder by date it was modified/created/accessed

Im trying to achieve the following:



A Folder contains a list of Sub folders, all created at different dates.



I need to retrun the Folder that was created most recently. 



 which is the best method to approach this using C# script?



thanks,







2 Replies

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi Alina, you can use the aqFolderInfo and aqFileSystem objects to acheive this as follows:




    function getLatestFolderInfo() {


      var subFolder,


          latestSubFolder;


      var rootFolder = "C:\\Temp";


      var rootFolderInfo = aqFileSystem["GetFolderInfo"]( rootFolder );


      var subFolders = rootFolderInfo["SubFolders"];


      while( subFolders["HasNext"]() ) {


        subFolder = subFolders["Next"]();


        Log["Message"]( subFolder.DateCreated + " : " + subFolder.Name );


        if ( latestSubFolder ) {


          if( subFolder.DateCreated > latestSubFolder.DateCreated ) {


            latestSubFolder = subFolder;


          }


        } else {


            latestSubFolder = subFolder;


        } 


      }


      if( latestSubFolder ) {


        Log["Message"]( latestSubFolder.Name + " : " + latestSubFolder.DateCreated );


      }


    }


     


    Hope this helps,


     


    Regards,


    Phil Baird

  • Alina's avatar
    Alina
    Occasional Contributor
    Hi Phil,



    Thanks a ton for your help, it worked first time!



    Great Stuff,



    Alina