"Jake" <> wrote in message
news:...
> Thanks for the reply -
> Any way to sort this by Date Created Acending? Its now sorting by
filename.
>
>
>
> "McKirahan" <> wrote in message
> news:SL2dnaqsVb6GsmbcRVn-...
> > "Jake" <> wrote in message
> > news:#...
> >> Im using the following code to display the contents of a directory:
> >>
> >> <%
> >> Set objFso = CreateObject("Scripting.FileSystemObject")
> >> Set objFiles = objFso.GetFolder(Server.MapPath("."))
> >> Set fileList = objFiles.Files
> >> For Each i in fileList
> >> response.write i.name & " - " & i.DateCreated & "<br>"
> >> next
> >> %>
> >> Is there a way I can sort this by Date Created so the most recent files
> > are
> >> on top?
> >>
> >> Thanks!
> >
> > Normally, I'd use ADO to sort the file names but ...
> >
> > Files are returned in ascending DateCreated sequence;
> > thus, building an array and report it backwards will work.
[snip]
I guess it's only my PC that displays files by DateCreated.
Here's a subroutine that may do what you want.
<%@ Language="VBScript" %>
<% Option Explicit
Call FileSort(".")
Sub FileSort(folder)
'****
'*
'* This subroutine lists files in a folder by DateCreated.
'*
'****
'*
'* Declare Constants
'*
Const cRS1 = "DateCreated"
Const cRS2 = "FileName"
'*
Const adChar = 129
Const adDate = 7
Const adLockBatchOptimistic = 4
Const adOpenStatic = 3
Const adUseClient = 3
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objGFO
Set objGFO = objFso.GetFolder(Server.MapPath(folder))
Dim objFIL
Set objFIL = objGFO.Files
Dim objRST
Set objRST = CreateObject("ADODB.RecordSet")
objRST.CursorLocation = adUseClient
objRST.LockType = adLockBatchOptimistic
objRST.CursorType = adOpenStatic
objRST.ActiveConnection = Nothing
objRST.Fields.Append cRS1, adDate
objRST.Fields.Append cRS2, adChar, 255
objRST.Open
'*
'* Files
'*
Dim intFIL
For Each intFIL In objFIL
objRST.AddNew
objRST.Fields(cRS1) = intFIL.DateCreated
objRST.Fields(cRS2) = intFIL.name
objRST.Update
Next
'*
'* Sort RecordSet
'*
objRST.Sort = cRS1 & " DESC"
objRST.MoveFirst
'*
'* Read RecordSet
'*
Do While Not objRST.EOF
Response.Write("<br>" & Trim(objRST.Fields(cRS2)) & " = " &
objRST.Fields(cRS1))
objRST.MoveNext
Loop
'*
'* Destroy Objects
'*
objRST.Close
Set objRST = Nothing
Set objFIL = Nothing
Set objGFO = Nothing
Set objFSO = Nothing
End Sub
%>
Of course you could always Shell out to the "dir" command.
<%@ Language="VBScript" %>
<% Option Explicit
Const cTXT = "~dir_o-d.txt"
Const cWSS = "%comspec% /c dir /o-d > "
Dim strWSS
strWSS = Server.MapPath(cTXT)
Dim objWSS
Set objWSS = CreateObject("WScript.Shell")
objWSS.Run cWSS & strWSS, 0, True
Set objWSS = Nothing
%>
Then use FSO to read this file.
|