I would like to sort the files using ASP Classic FSO by date.
Do I need to loop through all the files, put the dates into an array and then list the array by date order or is there a simpler way to do this using FSO alone?
Thanks,
Mike
Join Stack Overflow to learn, share knowledge, and build your career.
I would like to sort the files using ASP Classic FSO by date.
Do I need to loop through all the files, put the dates into an array and then list the array by date order or is there a simpler way to do this using FSO alone?
Thanks,
Mike
This function uses ADO Recordset to sort files:
http://www.roubaixinteractive.com/PlayGround/FSO/Sort_Folder_Contents.asp
I created a VBScript function SortFiles
which:
FileSystemObject
's Files
collection into a VBScript arrayDateLastModified
order (caveat: it's a slow sort, you can improve it with alternate algorithms)Here's my VBScript function SortFiles
:
Function SortFiles(files)
ReDim sorted(files.Count - 1)
Dim file, i, j
i = 0
For Each file in files
Set sorted(i) = file
i = i + 1
Next
For i = 0 to files.Count - 2
For j = i + 1 to files.Count - 1
If sorted(i).DateLastModified < sorted(j).DateLastModified Then
Dim tmp
Set tmp = sorted(i)
Set sorted(i) = sorted(j)
Set sorted(j) = tmp
End If
Next
Next
SortFiles = sorted
End Function
Sample use of the SortFiles
function:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim files
Set files = fso.GetFolder(SOME_PATH).Files
Dim file
For Each file in SortFiles(files)
Rem Do something with file ...
Next