read directory list

S

shank

I borrowed the below code from http://www.brainjar.com/asp/dirlist/ and
cannot get it to read my folder files. I don't get any errors or any output
to screen. I have the below folder permissions set to browse. Without using
the below page, I can browse the files. What did I miss?
thanks!

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder("c:\inetpub\wwwroot\bs\aa\")
%>
<% function MapURL(path)

dim rootPath, url

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

rootPath = Server.MapPath("/")
url = Right(path, Len(path) - Len(rootPath))
MapURL = Replace(url, "\", "/")

end function %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<% sub ListFolderContents(path)

dim fs, folder, file, item, url

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

'Display the target folder and info.

Response.Write("<li><b>" & folder.Name & "</b> - " _
& folder.Files.Count & " files, ")
if folder.SubFolders.Count > 0 then
Response.Write(folder.SubFolders.Count & " directories, ")
end if
Response.Write(Round(folder.Size / 1024) & " KB total." _
& "</li>" & vbCrLf)

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><a href=""" & url & """>" _
& item.Name & "</a> - " _
& item.Size & " bytes, " _
& "last modified on " & item.DateLastModified & "." _
& "</li>" & vbCrLf)
next

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

end sub %>
</body>
</html>
 
M

Mike Brind

shank said:
I borrowed the below code from http://www.brainjar.com/asp/dirlist/ and
cannot get it to read my folder files. I don't get any errors or any output
to screen. I have the below folder permissions set to browse. Without using
the below page, I can browse the files. What did I miss?
thanks!

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder("c:\inetpub\wwwroot\bs\aa\")
%>
dim fs, folder, file, item, url

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

'Display the target folder and info.

Response.Write("<li><b>" & folder.Name & "</b> - " _
& folder.Files.Count & " files, ")
if folder.SubFolders.Count > 0 then
Response.Write(folder.SubFolders.Count & " directories, ")
end if
Response.Write(Round(folder.Size / 1024) & " KB total." _
& "</li>" & vbCrLf)

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><a href=""" & url & """>" _
& item.Name & "</a> - " _
& item.Size & " bytes, " _
& "last modified on " & item.DateLastModified & "." _
& "</li>" & vbCrLf)
next

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

end sub %>
</body>
</html>

You need to actually call the sub at some point. Replace the first two
lines of code with the following:
<%
ListFolderContents("c:\inetpub\wwwroot\bs\aa\")
%>

A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top