I have this script to display all the files within the directory the script is in, but I will have a directory that will contain multiple folders, with documents in each.
What I envision is a webpage that dynamically lists all the folders, by开发者_StackOverflow社区 its name, then when you click it, it displays the list of files linked.
I want to do this, because this directory will have additional folders and files added to it.
This is the script I have that will work, IF I put it in each folder, so it isn't completely dynamic.
<h3>Resources/Documents</h3>
<ul>
<%
Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject")
Set MyFiles=MyDirectory.GetFolder(Server.MapPath("documents/standard_14"))
For each filefound in MyFiles.files
%>
<li>
<a href="documents/standard_14/<% =filefound.Name %>" target="blank"><% =filefound.Name %></a>
</li>
<% Next %>
</ul>
I am not familiar with ASP at all - any help is appreciated.
<% ListFolderContents(Server.MapPath("/path/to/main/folder")) %>
<% 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("<h2>"& folder.Name &"</h2>")
'Display a list of sub folders.
for each item in folder.SubFolders
ListFolderContents(item.Path)
next
'Display a list of files.
Response.Write("<ul>")
for each item in folder.Files
url = MapURL(item.path)
Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>")
next
Response.Write("</ul>")
end sub
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 %>
精彩评论