FSO Object - Order by date created

I'm using FSO object to list files in a folder. Is there a way to list the files by date created instead of the file name?

Here is my code...

<%
      Dim okToShow
      okToShow="Yes"

            'Build table for files
                  response.write "<table width=500>"
            'Header Row      
                  response.Write "<tr>"
                  response.write "<td width=250>" & "<b>" & "<font color=#000000>" & "Created" &  "</font>" & "</b>" & "</td>"
                  response.write "<td width=150>" & "<b>" & "<font color=#000000>" & "Files" & "</font>" & "</b>" & "</td>"
                  response.write "<td width=100>" & "<b>" & "<font color=#000000>" & "Size" &  "</font>" & "</b>" & "</td>"
                  response.write "<td width=100>" & "<b>" & "<font color=#000000>" & "Delete?" & "</font>" & "</td>"
                  response.write "</tr>"
            
            ' Show the Folders and files subroutine:
            Sub ShowFile(file)
                   if file = "upload_success.asp" or file = "deletefile.asp" then
                  If okToShow="Yes" Then
                  response.Write "<tr>"
                  response.Write "<td width=600 colspan=4>" & "</td>"
                  Response.Write "</tr>"
                  okToShow="No"
                  End If
               
                     else
               'write table row with files available

                  response.Write "<tr>"
                  response.write "<td width=250>" & "<font color=#000000>" & objFile.DateCreated &  "</font>" & "</td>"
                  response.Write "<td width=150>" & "<a href=""" & file & """>" & file & "</a>" & "</td>"
                  response.write "<td width=100>" & "<font color=#000000>" & objFile.Size & " bytes" & "</font>" & "</td>"
                  response.write "<td width=100><font color=#000000><a href='deletefile.asp?file=" & server.urlencode(objFile.Path) & "'>DELETE</a></font></td>"
                  Response.Write "</tr>"
                  end if
            End Sub
                  
            Const DIR = "./"

            ' Variables for our FileSystemObject objects
            Dim objFSO, objFolderObject, objFileCollection, objFile, objSubF

            ' A pair of integers for our random image selection
            Dim intFileNumberToUse, intFileLooper

            ' A "handle" to the file we choose to use
            Dim objImageFileToUse

            ' A variable to build our image tag
            Dim strImageSrcText

            ' Lets see what's in the directory:
            Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
            Set objFolderObject = objFSO.GetFolder(Server.MapPath(DIR))
            
            Set objFileCollection = objFolderObject.Files
            
            'Files within this folder
            For Each objFile in objFileCollection
                        ' Get a "handle" on the appropriate file
                        Set objImageFileToUse = objFile
                        If objImageFileToUse.Name <> "index.asp" and objImageFileToUse.Name <> "index.htm" Then
                              ShowFile(objImageFileToUse.Name)
                        End If
                        
            Next

            Set objFileCollection = Nothing
            Set objImageFileToUse = Nothing
            Set objFSO = Nothing
            Set objFolderObject = Nothing

            response.write "</table>"
            %></p>

Thanks
j
kevinbenedictAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dfu23Commented:
I don't think that you can sort the FSO object but you could read the results into an array and sort from there ...
0
kevinbenedictAuthor Commented:
Could you direct me how to do that as I'm just figuring this stuff out.

Thanks
0
dfu23Commented:
If you look at the example here:

http://www.asp101.com/samples/viewasp.asp?file=dir%5Flist%5Fsort%2Easp

You'll see that he uses a RecordSet to read the results of the FileSystemObject into ... and then sorts the RecordSet ... it should work fine for your purposes too. You would probably just want to do:

rstFiles.Sort = "date ASC"

OR

rstFiles.Sort = "date DESC"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

kevinbenedictAuthor Commented:
Thanks for the link. I'll check it out.
0
kevinbenedictAuthor Commented:
I'm real close to getting this resolved. I'm getting an "object expected error"  What am I missing on this line?

<td align="left" ><a href='deletefile.asp?file="<%= strPath & rst.Files.Fields("name").Value %>"'>Delete</a></td>

thanks
j
0
dfu23Commented:
Did you already figure this part out? Is it something like the following?

<td align="left" ><a href='deletefile.asp?file="<%= strPath & rstFiles.Fields("name").Value %>"'>Delete</a></td>
0
kevinbenedictAuthor Commented:
Yes. Sorry about that.

Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.