首页  ·  知识 ·  云计算
遍历指定目录下的所有文件
柳永法  http://www.yongfa365.com/  综合  编辑:dezai  图片来源:网络
%Sub ListFolderContents(
<%
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("
  • " & Folder.Name & " - " & 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("
      " & 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("
    • & url & """>" & Item.Name & " - " & Item.Size & " bytes, " & "last modified on " & Item.DateLastModified & "." & "
    • " & vbCrLf) Next Response.Write("
    " & vbCrLf) Response.Write("
  • " & 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 ListFolderContents(server.mappath("/")) %>
    本文作者:柳永法 来源:http://www.yongfa365.com/
    CIO之家 www.ciozj.com 微信公众号:imciow
       
    免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
    延伸阅读