ASP遍历目录 深度问题
<%SubFileList(Path)SetFSO=CreateObject("Scripting.FileSystemObject")ifnotfso.FolderEx...
<%
Sub FileList(Path)
Set FSO = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(path) then exit sub
Set folders = FSO.GetFolder(Path)'目录下所有对象
Set subfolders = folders.SubFolderson error resume next
For Each fl in subfolders
FileList(Path&"\"&fl.name)
response.Write Path&"\"&fl.name &"<br>"
Next
set folders=nothing
set files=nothing
set subfolders=nothing
Set FSO = Nothing
End SubFileList("C:")
%> 上面是我写的遍历C盘目录的ASP程序 使用过程中发现有些目录太深比如:C:\\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\Packages\Debugger\2052这个10层目录。我想只扫描前四五层目录。帮忙想想怎么设置只到C:\\Program Files\Microsoft SQL Server\90\Tools\Binn 后面不扫描了 展开
Sub FileList(Path)
Set FSO = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(path) then exit sub
Set folders = FSO.GetFolder(Path)'目录下所有对象
Set subfolders = folders.SubFolderson error resume next
For Each fl in subfolders
FileList(Path&"\"&fl.name)
response.Write Path&"\"&fl.name &"<br>"
Next
set folders=nothing
set files=nothing
set subfolders=nothing
Set FSO = Nothing
End SubFileList("C:")
%> 上面是我写的遍历C盘目录的ASP程序 使用过程中发现有些目录太深比如:C:\\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\Packages\Debugger\2052这个10层目录。我想只扫描前四五层目录。帮忙想想怎么设置只到C:\\Program Files\Microsoft SQL Server\90\Tools\Binn 后面不扫描了 展开
1个回答
2014-01-24
展开全部
用下面的代码,看加粗部份:<%Sub FileList(Path,cc)Set FSO = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(path) or cc>5 then exit sub
Set folders = FSO.GetFolder(Path)'目录下所有对象
Set subfolders = folders.SubFolderson error resume next
For Each fl in subfolders
FileList(Path&"\"&fl.name,cc+1)
response.Write Path&"\"&fl.name &"<br>"
Next
set folders=nothing
set files=nothing
set subfolders=nothing
Set FSO = Nothing
End SubFileList("C:",0)
%>
if not fso.FolderExists(path) or cc>5 then exit sub
Set folders = FSO.GetFolder(Path)'目录下所有对象
Set subfolders = folders.SubFolderson error resume next
For Each fl in subfolders
FileList(Path&"\"&fl.name,cc+1)
response.Write Path&"\"&fl.name &"<br>"
Next
set folders=nothing
set files=nothing
set subfolders=nothing
Set FSO = Nothing
End SubFileList("C:",0)
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询