根据“上次修改日期"循环浏览文件夹中的所有文件 [英] Loop through ALL files in a folder based on 'Last Modified Date'

查看:115
本文介绍了根据“上次修改日期"循环浏览文件夹中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按照上次修改日期"的降序浏览给定文件夹中的文件.

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.

  1. 是否存在允许FileSystemObject对文件进行排序的内置方法,还是我们绝对必须编写自定义排序例程?

  1. 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:

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

这篇关于根据“上次修改日期"循环浏览文件夹中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆