首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

asp fso遍历文件夹有关问题?初学者求高人指点

2012-02-04 
asp fso遍历文件夹问题?菜鸟求高人指点程序:functionbianli(path)foreachobjSubFolderinobjSubFoldersnowp

asp fso遍历文件夹问题?菜鸟求高人指点
程序:
        function   bianli(path)
        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
                              Response.Write   " <br> --- "
                                                  next
                      Response.Write   " <p> "
                      bianli(nowpath)         '调用递归
              next  
              set   objFolder=nothing
              set   objSubFolders=nothing
              set   fso=nothing
              conn.Close
      end   function

问题:1。这个程序如果根目录有文件遍历不出来?怎么改?
          2。如果目录下有二级目录   程序是怎么判断出来的。(我想根据是否二级或三级目录而变量给出不同的数值)

[解决办法]
你的意思是在一个页面里打印出来一个文件夹下的所有文件(包括子文件夹),还是一层一层的
[解决办法]
参考

Dim fo, f, fs, f1
Set fo = Createobject( "Scripting.Filesystemobject ")
Set f = fo.Getfolder(server.mappath(SERVER_PATH & UPLOAD_GLOBAL_PATH & path))

' '文件夹
Set fd = f.subfolders

For Each f1 In fd
tpl.setBVar "foldername ", f1.Name
tpl.setBVar "folderdate ", f1.DateLastModified
Next


' '文件
Set fs = f.files

For Each f1 In fs
tpl.setBVar "filename ", f1.Name
tpl.setBVar "filedate ", f1.DateLastModified
Next
Set fo = Nothing
Set f = Nothing
Set fd = Nothing
Set fs = Nothing
[解决办法]
好像只能遍历出所有的文件吧.文件夹是不行的.
[解决办法]
<%
function bianli(path)
set fso=server.CreateObject( "scripting.filesystemobject ")
on error resume next
set objFolder=fso.GetFolder(path)
for each objFile1 in objFolder.Files


Response.Write " <br> --- "
Response.Write objFile1.name
next
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> "
bianli(nowpath)
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
%>
<%
bianli( "D:\oa ")
%>

热点排行