Bra*_*rad 3 file-io asp-classic
我有这个脚本来显示脚本所在目录中的所有文件,但是我将有一个包含多个文件夹的目录,每个文件夹中包含文档.
我设想的是一个网页,它按名称动态列出所有文件夹,然后当你点击它时,它会显示链接的文件列表.
我想这样做,因为这个目录将添加额外的文件夹和文件.
这是我可以使用的脚本,如果我把它放在每个文件夹中,所以它不是完全动态的.
<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>
Run Code Online (Sandbox Code Playgroud)
我根本不熟悉ASP - 任何帮助表示赞赏.
<% 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 %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6065 次 |
| 最近记录: |