用asp遍历目录下文件的例子

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

<%

'By aloxy ,E-mail:szyjj@hotmail.com,OICQ:331622229

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." _

& 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)

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("/")

url = Right(path, Len(path) - Len(rootPath))

MapURL = Replace(url, "\", "/")

end function %>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航