473,434 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

Directory list sort order

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!
Jul 22 '05 #1
4 20839
"Jake" <sp******@alltel.net> wrote in message
news:#D**************@TK2MSFTNGP12.phx.gbl...
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.
<%
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(Server.MapPath("."))
Set fileList = objFiles.Files
'*
Dim arrFiles()
Dim intFiles
intFiles = 0
For Each i In fileList
intFiles = intFiles + 1
ReDim Preserve arrFiles(intFiles)
arrFiles(intFiles) = i.name & " - " & i.DateCreated
Next
'*
For intFiles = UBound(arrFiles) To 1 Step -1
response.write arrFiles(intFiles) & "<br>"
Next
'*
Set objFso = Nothing
Set objFiles = Nothing
%>
Jul 22 '05 #2
Thanks for the reply -
Any way to sort this by Date Created Acending? Its now sorting by filename.

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:SL********************@comcast.com...
"Jake" <sp******@alltel.net> wrote in message
news:#D**************@TK2MSFTNGP12.phx.gbl...
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.
<%
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(Server.MapPath("."))
Set fileList = objFiles.Files
'*
Dim arrFiles()
Dim intFiles
intFiles = 0
For Each i In fileList
intFiles = intFiles + 1
ReDim Preserve arrFiles(intFiles)
arrFiles(intFiles) = i.name & " - " & i.DateCreated
Next
'*
For intFiles = UBound(arrFiles) To 1 Step -1
response.write arrFiles(intFiles) & "<br>"
Next
'*
Set objFso = Nothing
Set objFiles = Nothing
%>

Jul 22 '05 #3
"Jake" <sp******@alltel.net> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...
Thanks for the reply -
Any way to sort this by Date Created Acending? Its now sorting by filename.
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:SL********************@comcast.com...
"Jake" <sp******@alltel.net> wrote in message
news:#D**************@TK2MSFTNGP12.phx.gbl...
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.
Jul 22 '05 #4
Thanks!
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:FK********************@comcast.com...
"Jake" <sp******@alltel.net> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...
Thanks for the reply -
Any way to sort this by Date Created Acending? Its now sorting by

filename.

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:SL********************@comcast.com...
> "Jake" <sp******@alltel.net> wrote in message
> news:#D**************@TK2MSFTNGP12.phx.gbl...
>> 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.

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: One's Too Many | last post by:
Ran into a strange problem today: 8.1.7 on AIX 4.3.3 Database and applications had been working fine for two years and all of a sudden a couple of regularly-run queries are now no longer...
13
by: .:mmac:. | last post by:
I am listing a set of files using the following script: <% set directory = Server.CreateObject("Scripting.FileSystemObject") set allfiles = directory.GetFolder(Server.MapPath("/mmm/lesson/"))...
0
by: Bob Darlington | last post by:
I am using A2002. In the User and Group Permissions dialog, the 'Object Name' list box appears to be listing forms which have recently been imported (from backup copies of the program) in an order...
11
by: James P. | last post by:
Hello, I have a report with the Priority field is used as sort order and grouping. The problem is the data in this Priority field if sorted in ascending order is: High, Low, and Medium. How...
7
by: Steve Crawford | last post by:
I am suffering some sort order confusion. Given a database, "foo", with a single character(4) column of data left padded with spaces I get: select * from foo order by somechars; somechars...
0
by: joseph speigle | last post by:
hi, To see the query results in native language see http://database.sarang.net/?inc=read&aid=5368&criteria=pgsql&subcrit=qna&id=&limit=20&keyword=&page=1 the simpler url is ...
2
by: adrian.chandler | last post by:
Hi all, I have been using letter and symbol codes such as GNU< GNU\ GNU} GNUˆ in an Access table. I was surprised to see that when the table was sorted on this field, the order is: GNUˆ...
5
by: Ethan Strauss | last post by:
Hi, I want to be able to create a custom sort order for a Sorted List. Specifically, I have a grid which goes from A1 to H12. The default sort gives me A10, A11, A1, A2 ... I would like to change...
0
by: Amar | last post by:
Hi, I have a generic list with a some objects of a particular class in it. I have implemented a IComparer for the the class and pass it to the List. The list.sort method works fine when the value...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.