以下是我认为会给你最好的结果:
首先将所有文件列出到断开连接的记录集中:
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
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:\your-folder-location").Files
list.AddNew
list("name").Value = f.Path
list("date").Value = f.DateLastModified
list.Update
Next
list.MoveFirst
然后,您可以按上次修改日期对它们进行排序:
list.Sort = "date DESC"
现在,您可以从列表顶部开始,逐步完成。
Dim foundApple
list.MoveFirst
Do Until list.EOF Or foundApple
Do Until objTextFile.AtEndOfStream
Set objTextFile = fso.OpenTextFile(list("name"), ForReading)
strLine = objTextFile.ReadLine()
If InStr(strLine, "apple") <> 0 then foundApple = True
Loop
' If foundApple = True Then (Do whatever stuff you need)
list.MoveNext
Loop
list.Close
- 我刚刚把这段代码脑残了。它没有经过测试。YMMV。