Sorting file list from the server.

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/71263?pagenum=1
04 November 2025, 18:14

Topic


bobby131313
Sorting file list from the server.
01 March 2018, 18:57


So I created a page so users can see and reuse their previously uploaded images, the code below grabs the file list (FileList).
Code:
Dim fs, f, Folder, fc, s, File, FileList, FolderInfo, FileName, Name
Set FolderInfo = Fso.GetFolder(PathSpec)
Set FileList = FolderInfo.Files
intFiles = FileList.Count
intFSize = FolderInfo.Size

This grabs them in the normal windows order. Given the time stamping during upload the oldest ones are always first so users with hundreds of images have to always go to the last page and scroll to the end to get recent images.
I have spent a month or so off and on googling trying to flip the order so the recent ones will be first.
Is this possible? Thanks in advance.

 

Replies ...


HuwR
02 March 2018, 11:09


you need to put them in an array or a recordset object and then sort that.
Something along the line of
Code:

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorLocation = 3 ' adUseClient
objRS.Fields.Append "Name", 200, 50 ' adVarChar
objRS.Fields.Append "created", 7 ' adDate
objRS.Open

imagespath = "C:\inetpub\wwwroot\_images\"

Dim FSObj, FOlderObj, FileCollObj
Set FSObj = Server.CreateObject("Scripting.FileSystemObject")

Set FolderObj = FSObj.GetFolder(imagespath)
Set FolderCollObj = FolderObj.SubFolders
For Each item in FolderCollObj
Set SubFolderObj = FSObj.GetFolder(FolderObj & "/" & item.name)
objRS.AddNew
objRS("Name") = item.name
objRS("created") = SubFolderObj.DateCreated
Next
objRS.Sort = "created DESC"
objRS.MoveFirst
Do UNTIL objRS.EOF
response.write "<a href=""gallery.asp?gallery=" & objRS(0) & """>"
response.write objRS(0) & " <BR><BR></A>"
objRS.movenext
Loop
bobby131313
02 March 2018, 16:01


Thanks Huw, I'll take a look at that today.
© 2000-2021 Snitz™ Communications