Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
610 views
in Technique[技术] by (71.8m points)

vbscript - Order of Files collection in FileSystemObject

In VBScript, I want to get a list of files in a folder ordered by creation date. I saw that in order to do that I will need to either use a record set (seems like an overkill to me) or sort the collection myself (I think I can avoid it and I want my code to be shorter).

Since I am the one creating the files, I create them with names that begin with the date (yyyy_mm_dd) so I though that if I can get the files at least ordered by name then I'm all set. Unfortunately, the MSDN documentation of the Files collection from FileSystemObject doesn't say anything about the order of the collection. Does anyone know of some other secret documentation or something like that that can be more specific?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is it really too much code to sort?

set fso = CreateObject("Scripting.FileSystemObject")

Set outputLines = CreateObject("System.Collections.ArrayList")
for each f in fso.GetFolder(".").files
  outputLines.Add f.Name
next
outputLines.Sort() ' 5 lines...

For Each outputLine in outputLines
  set file = fso.GetFolder(".").files.item (outputLine&"")
  Wscript.Echo file.name ' TODO: your thing here
Next

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...