Click to See Complete Forum and Search --> : Displaying a folder's contents alphabetically
I'm displaying a folder's contents and I want to know how to display the files alphabetically. Is this possible? If so, how do I do it?
What are you using to display the folder's contents? A listbox? Just set the Sorted property to True and they will be sorted alphabetically.
a listbox? not at all. I'm doing this:
<%@ Language="VBScript" %>
<html>
<head>
<%
'Define the File System Object and set variables
Dim FSO, Folder, FolderContents, FileItem
Set FSO = CreateObject("Scripting.FileSystemObject") 'Create FSO
Set Folder = FSO.GetFolder("C:\muzik\hip-hop - rap") 'Declare folder to have contents displayed
Set FolderContents = Folder.Files
%>
<title><%= Response.Write(Folder.Name) %></title>
<style type="text/css">
body, table {color:#000000; font-family:Verdana; font-size:11px}
</style>
</head>
<body>
<form action="Confirm.asp" method="post">
<table border="0" cellpadding="4" cellspacing="0">
<tr><td bgcolor="darkgray" align=left>
</td><td bgcolor="darkgray" align=left>
<font size="2"><b>File</b></font>
</td><td bgcolor="darkgray" align=left>
<font size="2"><b>Size (mb)</b></font>
</td></tr>
<%
'Display each file's name and size with a checkbox
Response.Write("<font size=5>Contents of: " & Folder & "<p>")
Dim FileSize
For Each FileItem In FolderContents
FileSize = Round(FileItem.Size / 1000000, 1) 'Converts file size into MB, rounds to tenth place
Response.Write("<tr><td bgcolor=lightgrey align=left>")
Response.Write("<input type='checkbox'>")
Response.Write("</td><td bgcolor=lightgrey align=left>")
Response.Write(FileItem.Name) 'Displays file name
Response.Write("</td><td bgcolor=lightgrey align=right>")
Response.Write(FileSize) 'Displays file size in MB
Response.Write("</td></tr>")
Next
%>
</td></tr>
<tr><td colspan=3>
<input type="submit" value="Delete">
</td></tr>
</table>
</form>
</body>
</html>
Im displaying the files to a page, I need to sort them within the for loop somehow.
:eek:eek:eek:
I'm still only learning VBScript, only know a limited amount of stuff. This is out of my league for now, sorry :(.
da_silvy
Dec 11th, 2000, 01:17 AM
you could look around some other sites to see if they can do it, i.e http://www.4guysfromrolla.com
Danial
Mar 15th, 2002, 03:50 PM
Originally posted by voyd1
Im displaying the files to a page, I need to sort them within the for loop somehow.
Yep you could use a sort function. First read all the file names to an Array and then use the sort function to sort that array and the output the content of the sorted array.
You should be able to find plenty of sort algorithm in this forum just adapt it for ASP.
Shouldnt be that hard.
Hope this helps
Danial
Mar 18th, 2002, 05:02 PM
Here is a link, i think this is what exactly you are lookikng for
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=118
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.