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