Loop through ALL files in a folder based on 'Last Modified Date'

后端 未结 1 1009
慢半拍i
慢半拍i 2020-12-05 16:58

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 mo

相关标签:
1条回答
  • 2020-12-05 17:12

    You could read the file names and dates into a disconnected recordset and sort that 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
    
    0 讨论(0)
提交回复
热议问题