Scroll ALL files in a folder based on "Last Modified Date"

I need to scroll through the files in a given folder in descending order of "Last Modified Date".

In the first iteration of the loop, I need to open the last modified file for reading and close it. In the second iteration, I need to open the second last updated file for reading, close it, etc.

  • Is there a built-in method that allows FileSystemObject sort files, or do we absolutely need to write a normal sort procedure?

  • If we need to perform the usual sorting procedure, is it possible to write this without several functions? those. all code in the main function.

  • Speed ​​is a problem, because you need a lot of files to sort. Therefore, any user procedures must be effective.

+6
source share
1 answer

You can read the file names and dates in the disabled recordset and sort it by date:

 Set fso = CreateObject("Scripting.FileSystemObject") Set list = CreateObject("ADOR.Recordset") list.Fields.Append "name", 200, 255 list.Fields.Append "date", 7 list.Open For Each f In fso.GetFolder("C:\some\where").Files list.AddNew list("name").Value = f.Path list("date").Value = f.DateLastModified list.Update Next list.MoveFirst Do Until list.EOF WScript.Echo list("date").Value & vbTab & list("name").Value list.MoveNext Loop list.Sort = "date DESC" list.MoveFirst Do Until list.EOF WScript.Echo list("date").Value & vbTab & list("name").Value list.MoveNext Loop list.Close 
+9
source

Source: https://habr.com/ru/post/943916/


All Articles