Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...