[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

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
0
kevinbenedict
Asked:
kevinbenedict
  • 4
  • 3
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now