当前位置: 首页 > 图文教程 > 网络编程 > ASP > 关于创建多级文件夹的ASP函数实例

ASP
ASP实例:是否支持XmlHttp组件的判断
ASP对XML文档中文本的增加、删除、修改、查看
ASP操作XML文件的主要方法和实现
asp控制xml数据库的6段代码
ASP操作XML的类
ASP关于类的Let,Set和Get的用法的异同
ASP错误解决:800a003a错误
XMLHTTP Post Form时的表单乱码
IIS7.0在Vista系统下安装注意事项
asp文件打不开的原因
asp根据表单自动生成sql语句的函数
彻底解决XP下IIS无法解释ASP和PHP的问题
ASP教程:0177:800401f3错误解决
Service Unavailable错误的解决
ASP留言本教程
ASP教程:6大对象和数据库操作简单学
配置IIS蜜罐与黑客攻击
WEB共享与IIS相结合快速建立本地网站
IIS6架设网站的问题总结
HTTP 500 - 内部服务器错误的解决

关于创建多级文件夹的ASP函数实例


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

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

以下为引用的内容:
'--------------------------------
'自动创建指定的多级文件夹
'strPath为绝对路径
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 = Server.MapPath("a/b/c")
If AutoCreateFolder(MyPath) Then
        Response.Write "创建文件夹成功"
Else
        Response.Write "创建文件夹失败"
End If