Sorting file list from the server. - Posted (1463 Views)
Senior Member
bobby131313
Posts: 1163
1163
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.
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Forum Admin
HuwR
Posts: 20611
20611
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
Posted
Senior Member
bobby131313
Posts: 1163
1163
Thanks Huw, I'll take a look at that today.
 
You Must enter a message