Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

FSO Object - Order by date created

Posted on 2004-10-25
7
Medium Priority
?
385 Views
Last Modified: 2008-02-26
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
Comment
Question by:kevinbenedict
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:dfu23
ID: 12400455
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
 

Author Comment

by:kevinbenedict
ID: 12400640
Could you direct me how to do that as I'm just figuring this stuff out.

Thanks
0
 
LVL 14

Accepted Solution

by:
dfu23 earned 800 total points
ID: 12400832
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:kevinbenedict
ID: 12400838
Thanks for the link. I'll check it out.
0
 

Author Comment

by:kevinbenedict
ID: 12402068
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
 
LVL 14

Expert Comment

by:dfu23
ID: 12402998
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
 

Author Comment

by:kevinbenedict
ID: 12403057
Yes. Sorry about that.

Thanks for your help.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question