...

View Full Version : Files in a folder



codefox
03-03-2003, 10:47 AM
Hi all,

I got this piece of code from a link on this forum itself. It is to list in a tree structure all the files and subfolders underneath a certain folder. The code being used is as follows

==============================================
<%@ LANGUAGE="VBScript" %>
<%
Response.CacheControl = "Private"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<% '***************************************************************************
'* ASP Directory Listing *
'* *
'* Do not remove this notice. *
'* *
'* Copyright 1999, 2000 by Mike Hall. *
'* Please see http://www.brainjar.com for documentation and terms of use. *
'***************************************************************************
%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ASP Directory Listing Demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style/stds.css" />
</head>
<body>


<ul>
<%
Dim ctryCode
ctryCode = trim(Request.QueryString ("ctryCode"))

if ctryCode = "eos" then
Response.Write ("<div align=center><h1>EOS</h1></div>")
ListFolderContents(Server.MapPath("/EOST"))
end if

%>
</ul>

</body>
</html>

<% sub ListFolderContents(path)

dim fs, folder, file, item, url

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)

Response.Write("<font class=dnb-topic-light-bg><li><b>" & folder.Name & "</b></font>")

Response.Write("<ul>" & vbCrLf)

'Display a list of sub folders.

for each item in folder.SubFolders
ListFolderContents(item.Path)
next

'Display a list of files.

for each item in folder.Files
url = MapURL(item.path)
Response.Write("<li><font class=dnb-link-light-bg><a href=""" & url & """ target=_doc>" & item.Name & "</a></font></li>" & vbCrLf)
next

Response.Write("</ul>" & vbCrLf)

Response.Write("</li>" & vbCrLf)

end sub

function MapURL(path)

dim rootPath, url

'Convert a physical file path to a URL for hypertext links.

rootPath = Server.MapPath("/")
on error resume next
url=path
MapURL = Replace(url, "\", "/")

end function %>
============================================
now what i find is that the subfolders/files are being listed in ascednding order of creation/modified date rather than alphabetically.

how do i get the listing of all files/subfolders in alphabetical order?

Thanks in advance, mates!

oracleguy
03-03-2003, 11:15 PM
The best idea would be to re-write the above code to put all the files into an array then write a sub to alphabatize the array. Then once thats done, you output the array onto the page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum