asp遍历文件夹

ASP/Visual Basic代码
  1. '遍历文件夹  
  2. sub ListFolderContents(path)   
  3.     dim fs, folder, file, item, url   
  4.     set fs = CreateObject("Scripting.FileSystemObject")   
  5.     set folder = fs.GetFolder(path)   
  6.        
  7.     Response.Write("<li><b>" & folder.Name & "</b> - " & folder.Files.Count & " files, " & folder.SubFolders.Count & " directories." & vbCrLf & "<ul>" & vbCrLf)   
  8.        
  9.        
  10.     for each item in folder.SubFolders   
  11.         ListFolderContents(item.Path)   
  12.     next   
  13.        
  14.     for each item in folder.Files   
  15.         Response.Write("<li><a href=""" & MapURL(item.path) & """ target='_blank'>" & item.Name & "</a> - " & item.path & "</li>" & vbCrLf)   
  16.     next   
  17.        
  18.     Response.Write("</ul>" & vbCrLf)   
  19.        
  20.     Response.Write("</li>" & vbCrLf)   
  21.   
  22. end sub   
  23.   
  24. function MapURL(path)   
  25.     MapURL = Replace(Right(path, Len(path) - Len(Server.MapPath("/"))), "\", "/") 
  26. end function 
  27.  
  28. ListFolderContents("D:\web\")  
如果您觉得我的文章有帮助,请随意赞赏!

此处评论已关闭