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

ASP
ASP优化:几招提高ASP性能的最佳选择
ASP进阶:用ASP制作统计饼图、柱状图等
ASP应用进阶 ASP Error对象的相关知识
ASP常见数学函数 Abs Atn Cos 等详解
ASP优化 用数据绑定实现高效率动态网页
用着放心 为你的ASP程序作一个负载测试
ASP+Access的安全隐患以及解决方法
ASP中将视频文件转换成.flv格式
经典!5分钟编写一个ASP论坛
ASP实现小偷程序原理和简单示例
用ASP木马实现FTP和解压缩
如何用ASP编写网站统计系统
response.write与之间的区别
asp操作excel文件的函数
如何有效提高asp页面的访问速度
JS+ASP打造无刷新新闻列表
使用VB将ASP代码封装生成DLL文件
用ASP打造一个小型的网页BBS系统
ASP网站的漏洞分解以及入侵防范方法
破解网站发布系统 ASP生成静态页面方法

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 31 ::
收藏到网摘: 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