读书人

asp中怎么实现目录上 子目录与文件 的

发布时间: 2012-08-31 12:55:03 作者: rapoo

asp中如何实现目录下 子目录与文件 的同时显示
asp中如何实现目录下 子目录与文件 的同时显示?

[解决办法]
'遍历文件夹
sub ListFolderContents(path)
dim fs, folder, file, item, url
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)

Response.Write("<li><b>" & folder.Name & "</b> - " & folder.Files.Count & " files, " & folder.SubFolders.Count & " directories." & vbCrLf & "<ul>" & vbCrLf)


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

for each item in folder.Files
Response.Write("<li><a href=""" & MapURL(item.path) & """ target='_blank'>" & item.Name & "</a> - " & item.path & "</li>" & vbCrLf)
next

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

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

end sub

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

ListFolderContents("D:\web\")

读书人网 >ASP

热点推荐