递归列出文件夹下所有文件

<%
dim fso
set fso=server.createobject("scripting.filesystemobject")
function ShowFolder(byval folderPath,byval n)
   dim strIndent,i,item,file,folder
   strIndent=""
   for i=1 to n
       strIndent=strIndent & "  "
   next
   set folder=fso.getfolder(folderPath)
   if folder.SubFolders.count<=0 then
       for each file in folder.files
           response.write strIndent & "|- 文件 -> " & file.name & "<br>" & vbcrlf
       next
   else
       for each item in folder.subfolders
           response.write strIndent & "|- 目录 ->" & item.Name & "<br>" & vbcrlf
           call ShowFolder(item.path,n+1)
       next
       for each file in folder.files
           response.write strIndent & "|- 文件 -> " & file.name & "<br>" & vbcrlf
       next
   end if
end function
call ShowFolder(server.mappath("MyFolder"),1)
set fso=nothing
%>

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据