网络编程
位置:首页>> 网络编程>> Asp编程>> asp函数遍历文件夹代码

asp函数遍历文件夹代码

 来源:cloudgamer 发布时间:2010-06-21 10:38:00 

标签:文件夹,asp,函数

使用fso对象遍历指定文件夹函数:

'遍历文件夹
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:\aspxhome.com\")

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com