网络编程
位置:首页>> 网络编程>> Asp编程>> ASP使用fso遍历文件及文件夹列出文件名

ASP使用fso遍历文件及文件夹列出文件名

  发布时间:2008-10-27 19:32:00 

标签:fso,文件夹,文件,组件,asp

调用bianli()函数,这里是遍历F:盘,bianli("F:\")'这里设置文件夹路径,你可以改为其它文件夹路径。

 

<%@ Language=VBscrīpt 

    function bianli(path)
        dim fso            'fso对象
        dim objFolder      '文件夹对象
        dim objSubFolders  '子文件夹集合
        dim objSubFolder   '子文件夹对象
        dim objFiles       '文件集合
        dim objFile        '文件对象

        set fso=CreateObject("scrīpting.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:\")
%>

 

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


<%@ Language=VBscrīpt %>
<%
 Response.contentType = "application/xml"
 Response.Expires = 0 
    function bianli(path)
        dim fso            'fso对象
        dim objFolder      '文件夹对象
        dim objFiles       '文件集合
        dim objFile        '文件对象
set fso=CreateObject("scrīpting.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
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com