加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

ASP遍历文件及文件夹

(2012-03-15 23:05:24)
标签:

子文件夹

对象

遍历

调用

当前目录

教育

分类: 2012-03

<%@ Language=VBscript %>
<%
    function bianli(path)
        dim fso            'fso对象
        dim objFolder      '文件夹对象
        dim objSubFolders '子文件夹集合
        dim objSubFolder   '子文件夹对象
        dim objFiles       '文件集合
        dim objFile        '文件对象

        set fso=server.CreateObject("scripting.filesystemobject")   
        on error resume next
        set ōbjFolder=fso.GetFolder(path)'创建文件夹对象
        set ōbjSubFolders=objFolder.Subfolders'创建的子文件夹对象
        for each objSubFolder in objSubFolders
            nowpath=path + "\\" + objSubFolder.name
            Response.Write nowpath
            set ōbjFiles=objSubFolder.Files
            for each objFile in objFiles
                Response.Write "<br>---"
                Response.Write objFile.name
            next
            Response.Write "<p>"
            bianli(nowpath)    '调用递归
        next
        set ōbjFolder=nothing
        set ōbjSubFolders=nothing
        set fso=nothing
    end function
%>
<%
    bianli("F:\") '调用bianli()函数,这里是遍历F:盘
%>

遍历某文件夹下文件,并输出为XML

<%@ Language=VBscript %>
<%
Response.contentType = "application/xml"
Response.Expires = 0
    function bianli(path)
        dim fso            'fso对象
        dim objFolder      '文件夹对象
        dim objFiles       '文件集合
        dim objFile        '文件对象

        set fso=server.CreateObject("scripting.filesystemobject")   
        on error resume next
        set ōbjFolder=fso.GetFolder(path)'创建文件夹对象
     Response.Write "<?xml version=""1.0"" encoding=""GB2312""?>"
     Response.Write ("<swf>")
            set ōbjFiles=objFolder.Files
            for each objFile in objFiles
                Response.Write ("<swf game='"&objFile.name&"'/>")
            next
    Response.Write ("</swf>")
        set ōbjFolder=nothing
        set ōbjSubFolders=nothing
        set fso=nothing
    end function
%>
<%
    bianli(Server.MapPath("/")+"\pic") '调用bianli()函数,这里是遍历当前目录下的pic文件夹
%>

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有