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

ASP
生成像资源管理器一样的树形目录
将连接数据库的代码隐藏在DLL中
ASP中从数据库读取二进制文件数据代码
asp查询xml的代码,实现了无刷新、模糊查询功能
一个asp函数, 解决SQL Injection漏洞
在ASP中利用COM组件开发Web应用程序
关于如何利用COM+,来提高ASP执行权限的问题!
升级MD5.ASP,打造完全动态不重复的安全加密代码
ASP安全检测与过滤函数SafeCheck
在ASP中,用JScript脚本实现分页的另类办法
查看服务器Application/Session变量工具
自己写的一个简单ASP调用存储过程查询
ASP登陆验证页应做的安全问题
使用ASP与javascript配合实现多个复选框数据关联显示
Windows 2003下不注册组件用ASP发邮件
数据分页方法新思路,速度非常快!
ASP程序中同一个用户不允许同时登陆两次
分栏显示记录集的表格演示,并实现了分页
关于Adodb.Stream的写数据库数据到客户端文件的实践
将ASP的Debug变得简单的两个函数

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


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