当前位置: 首页 > 图文教程 > 网络编程 > ASP > 在ASP中自动创建多级文件夹的函数(使用FSO)

ASP
保护 XML Web 服务免受黑客攻击
开发BtoC电子商务系统(ASP.NET)
用asp.net实现的把本文推荐给好友功能
尝尝ASP.NET中的小甜饼
web.config一个中文解释
使用ASP.NET加密口令
在SQL Server中保存和输出图片
ASP 中健壮的页结构的异常处理
如何使你的机器运行ASP?
asp(Active Server Page)的语言特性
关于inc文件
IE4 的 模 式 对 话 框 设 计
亲密接触ASP.net(6)
亲密接触ASP.Net(7)
用ASP.Net写一个发送ICQ信息的程序
用ASP.Net编写的查询域名的程序
使用 ASP+ 列表绑定控件(上)
使用 ASP+ 列表绑定控件(中)
使用 ASP+ 列表绑定控件(下)
揭开ASP神秘面纱(1)

在ASP中自动创建多级文件夹的函数(使用FSO)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 57 ::
收藏到网摘: n/a

 

    FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.

函数:
 
' --------------------------------
' 自动创建指定的多级文件夹
' strPath为绝对路径
' 引用请保留版权
' by im286_Anjer
' 2005-4-3
Function AutoCreateFolder(strPath) ' As Boolean
        On Error Resume Next

        Dim astrPath, ulngPath, i, strTmpPath
        Dim objFSO

        If InStr(strPath, "\") <=0 Or InStr(strPath, ":") <= 0 Then
                AutoCreateFolder = False
                Exit Function
        End If
        Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
        If objFSO.FolderExists(strPath) Then
                AutoCreateFolder = True
                Exit Function
        End If
        astrPath = Split(strPath, "\")
        ulngPath = UBound(astrPath)
        strTmpPath = ""
        For i = 0 To ulngPath
                strTmpPath = strTmpPath & astrPath(i) & "\"
                If Not objFSO.FolderExists(strTmpPath) Then
                        ' 创建
                        objFSO.CreateFolder(strTmpPath)
                End If
        Next
        Set objFSO = Nothing
        If Err = 0 Then
                AutoCreateFolder = True
        Else
                AutoCreateFolder = False
        End If
End Function
 


调用方法:

MyPath = "C:\a\b\c\"
If AutoCreateFolder(MyPath) Then
        Response.Write "创建文件夹成功"
Else
        Response.Write "创建文件夹失败"
End If