RSS
热门关键字:  下载  cms  模版  开源  dedecms
当前位置 :| 主页 > 站长学院 > 服务器 >

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

来源:互连网 作者:佚名 时间:2005-10-22 Tag: 点击:

<%
'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 %>


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
热点关注
相关文章