kevinbenedict
asked on
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.P ath) & "'>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("Scrip ting.FileS ystemObjec t")
Set objFolderObject = objFSO.GetFolder(Server.Ma pPath(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
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=
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("Scrip
Set objFolderObject = objFSO.GetFolder(Server.Ma
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
End If
Next
Set objFileCollection = Nothing
Set objImageFileToUse = Nothing
Set objFSO = Nothing
Set objFolderObject = Nothing
response.write "</table>"
%></p>
Thanks
j
I don't think that you can sort the FSO object but you could read the results into an array and sort from there ...
ASKER
Could you direct me how to do that as I'm just figuring this stuff out.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the link. I'll check it out.
ASKER
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").V alue %>"'>Delete</a></td>
thanks
j
<td align="left" ><a href='deletefile.asp?file=
thanks
j
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").Va lue %>"'>Delete</a></td>
<td align="left" ><a href='deletefile.asp?file=
ASKER
Yes. Sorry about that.
Thanks for your help.
Thanks for your help.