天涯之外

导航

ASP遍历文件、文件夹

<%
Function SubFolders(Path)
      Dim fso            'fso对象
      Dim objFolder      '文件夹对象
      Dim objSubFolders  '子文件夹集合
      Dim objSubFolder   '子文件夹对象
      Dim objFiles       '文件集合
      Dim objFile        '文件对象
 
      Set fso=server.CreateObject("scripting.filesystemobject")
      Set objFolder=fso.GetFolder(Path)'创建文件夹对象
      Set objSubFolders=objFolder.Subfolders'创建的子文件夹对象
      For Each objSubFolder In objSubFolders
            nowpath=path + "\" + objSubFolder.name
            Response.Write nowpath
            Set objFiles=objSubFolder.Files
            For Each objFile In objFiles
                  Response.Write "<br>---"
                  Response.Write objFile.name
            Next
            Response.Write "<p>"
            SubFolders(nowpath)    '调用递归
      Next
      Set objFolder=nothing
      Set objSubFolders=nothing
      Set fso=nothing
End Function
%>

<%
'=============调用示例
SubFolders(Server.MapPath("/"))
%>

posted on 2009-11-12 16:58  天涯之外  阅读(454)  评论(0编辑  收藏  举报