Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I list the items in a dir by their date? 2

Status
Not open for further replies.

help120

Technical User
Apr 15, 2001
198
US
I've this code that will list every file type in a dir and list it in alphabetical order. How can I list it so it shows the last file uploaded first? code can be viewed here.. #######################code####################
<br>
<div align=&quot;center&quot;>
<center>
<TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0 width=&quot;100%&quot;
style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#000000&quot;>
<TR BGCOLOR=&quot;#AD7500&quot;><TD width=&quot;147&quot;>
<p style=&quot;margin-top: 0; margin-bottom: 0&quot;><FONT COLOR=&quot;#FFFFFF&quot;><B>Filename:</B></FONT></TD>
<TD width=&quot;120&quot;>
<p style=&quot;margin-top: 0; margin-bottom: 0&quot;><FONT COLOR=&quot;#FFFFFF&quot;><B>
Size:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </B></FONT></TD><TD width=&quot;100&quot;>
<p style=&quot;margin-top: 0; margin-bottom: 0&quot;><FONT COLOR=&quot;#FFFFFF&quot;><B>File type:</B></FONT></TD>
<TD width=&quot;146&quot;>
<p style=&quot;margin-top: 0; margin-bottom: 0&quot;><FONT COLOR=&quot;#FFFFFF&quot;><B>
Date created:</B></FONT></TD>
<%
' Create an instance of the FileSystemObject
Set MyFileObject=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
' Create Folder Object
Set MyFolder=MyFileObject.GetFolder(Server.MapPath(&quot;shared&quot;))
'Loop trough the files in the folder
FOR EACH thing in MyFolder.Files
%>
<TR BGCOLOR=&quot;#F7F7E7&quot;><TD bgcolor=&quot;#906304&quot; width=&quot;147&quot;><A HREF=&quot;shared/<%=thing.Name%>&quot;><%=thing.Name%></A><p
style=&quot;margin-top: 0; margin-bottom: 0&quot;>&nbsp;</TD>
<TD ALIGN=RIGHT bgcolor=&quot;#906304&quot; width=&quot;120&quot; valign=&quot;top&quot;><font color=&quot;#FFFFFF&quot;><%=thing.Size%></font><p style=&quot;margin-top: 0; margin-bottom: 0&quot;>
bytes</TD>
<TD bgcolor=&quot;#906304&quot; width=&quot;100&quot;><font color=&quot;#FFFFFF&quot;><%=thing.Type%></font><p
style=&quot;margin-top: 0; margin-bottom: 0&quot;>&nbsp;</TD><TD bgcolor=&quot;#906304&quot;
width=&quot;146&quot;><font color=&quot;#FFFFFF&quot;><%=thing.DateCreated%></font><p
style=&quot;margin-top: 0; margin-bottom: 0&quot;>&nbsp;</TD>
<%
NEXT
%>
</TABLE></center>
</div>
<br>

</td>
</tr>
</table>
</center>
</div>
 
U should create an array and store all the info and then sort the array by date
________
George, M
 
I'm dumb.. speak to me as an asp newbie please. :0)
 
I've made some code for you. I hope this will help you. If u need explications please tell me.
here there are:
Code:
<br>
<div align=&quot;center&quot;>
<center>
<TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0 width=&quot;100%&quot; 
style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#000000&quot;>
<TR BGCOLOR=&quot;#AD7500&quot;><TD width=&quot;147&quot;>
<p style=&quot;margin-top: 0; margin-bottom: 0&quot;><FONT COLOR=&quot;#FFFFFF&quot;><B>Filename:</B></FONT></TD>
<TD width=&quot;120&quot;>
<p style=&quot;margin-top: 0; margin-bottom: 0&quot;><FONT COLOR=&quot;#FFFFFF&quot;><B>
Size:        </B></FONT></TD><TD width=&quot;100&quot;>
<p style=&quot;margin-top: 0; margin-bottom: 0&quot;><FONT COLOR=&quot;#FFFFFF&quot;><B>File type:</B></FONT></TD>
<TD width=&quot;146&quot;>
<p style=&quot;margin-top: 0; margin-bottom: 0&quot;><FONT COLOR=&quot;#FFFFFF&quot;><B>
Date created:</B></FONT></TD>
<%
' Create an instance of the FileSystemObject
Set MyFileObject=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
' Create Folder Object
Set MyFolder=MyFileObject.GetFolder(&quot;c:\&quot;)
'Loop trough the files in the folder
dim files()
nr=MyFolder.Files.Count
redim files(nr,4)
i=1
FOR EACH thing in MyFolder.Files
	files(i,1)=thing.Name
	files(i,2)=thing.Size
	files(i,3)=thing.Type
	files(i,4)=thing.DateCreated
	i=i+1
NEXT
'sorting
'this is an simple sorting program
for j=1 to nr
	for i=1 to nr-1
		if files(i,4)<files(i+1,4) then
			t1=files(i,1)
			t2=files(i,2)
			t3=files(i,3)
			t4=files(i,4)
			
			files(i,1)=files(i+1,1)
			files(i,2)=files(i+1,2)
			files(i,3)=files(i+1,3)
			files(i,4)=files(i+1,4)
			
			files(i+1,1)=t1
			files(i+1,2)=t2
			files(i+1,3)=t3
			files(i+1,4)=t4
		end if
	next
next
for i=1 to nr 
%>
<TR BGCOLOR=&quot;#F7F7E7&quot;><TD bgcolor=&quot;#906304&quot; width=&quot;147&quot;><A HREF=&quot;shared/<%=files(i,1)%>&quot;><%=files(i,1)%></A><p 
style=&quot;margin-top: 0; margin-bottom: 0&quot;> </TD>
<TD ALIGN=RIGHT bgcolor=&quot;#906304&quot; width=&quot;120&quot; valign=&quot;top&quot;><font color=&quot;#FFFFFF&quot;><%=files(i,2)%></font><p style=&quot;margin-top: 0; margin-bottom: 0&quot;>
bytes</TD>
<TD bgcolor=&quot;#906304&quot; width=&quot;100&quot;><font color=&quot;#FFFFFF&quot;><%=files(i,3)%></font><p 
style=&quot;margin-top: 0; margin-bottom: 0&quot;> </TD><TD bgcolor=&quot;#906304&quot; 
width=&quot;146&quot;><font color=&quot;#FFFFFF&quot;><%=files(i,4)%></font><p 
style=&quot;margin-top: 0; margin-bottom: 0&quot;> </TD> 
<%
next
%>
</TABLE></center>
</div>
<br>

</td>
</tr>
</table>
</center>
</div>
________
George, M
 
TIGHT! Thanks man, that's what I've been looking for.
 
The following is twice as fast.
No need to revist I=1 because I = J - 1 is already the least of all J thru NR.
for j=1 to nr
'****for i=1 to nr-1
for i=J to nr-1
if files(i,4)<files(i+1,4) then
.........
end if
next
next
Compare Code (Text)
Generate Sort in VB or VBScript
 
Could you guys explain this in a little more detail?
 
Better still, because it only moves when higher than all previous items.
for j = 1 to nr
'****for i=1 to nr - 1
for i = J + 1 to nr -1
if files(i,4)<files(J,4) then
'.... Replace all I+1 with J
end if
next
next
In the previous post, change &quot;least&quot; to &quot;highest&quot; and &quot;of all J thru NR.&quot; to &quot;of all J-1 thru NR.&quot;
Compare Code (Text)
Generate Sort in VB or VBScript
 
Shoot. Change Nr-1 to NR
' For every item (J)
for j = 1 to nr
' look at every item (I) further in the table and find
' the highest of all J thru NR
for i = J + 1 to nr
' If item(I)< item(J) then swap places
if files(i,4)<files(J,4) then
'.... Replace all I+1 with J
end if
' try next item(I)
next
' go to next item(J), find the highest of J thru NR
' then put it in Item(J)
next
Compare Code (Text)
Generate Sort in VB or VBScript
 
This was an simple sort algorithm, but like i saied you could find your own sort algorithm... ________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top