I need to loop through the files in a given folder in descending order of 'Last Modified Date'.
In the first iteration of the loop I need to be able to open the most recently modified file for reading and close it. In the second iteration, I need to be able to open the 2nd most recently updated file for reading and close it etc.
Is there a built in method that allows a
FileSystemObject
to sort the files or do we absolutely have to write custom sorting routine?If we have to go with a custom sorting routine, is it possible to write this without having multiple functions? i.e. all code in the a main function.
Speed is a concern since there are to be a lot of files to sort through. Therefore any custom procedures should be efficient.
You could read the file names and dates into a disconnected recordset and sort that by date: