FSO操作类asp创建文件夹

FSO操作类
cls_FileObj.asp


VBScript code
<%Class clsFileObj        Private Fso '对象        Public FsoObj  '公共接口对象                '初始化,构造函数        Private Sub Class_Initialize                Set Fso = Server.CreateObject("Scripting.FileSystemObject")                Set FsoObj = Fso        End Sub        '结束,释构函数        Private Sub Class_Terminate                Set Fso = Nothing                Set FsoObj = Nothing        End Sub        '------------------------------------------------判断文件夹是否存在--------        '存在则返回True,否则返回False        '参数FolderDir为文件的绝对路径        Public Function IsFolderExists(FolderDir)                If Fso.FolderExists(FolderDir) Then                        IsFolderExists = True                Else                        IsFolderExists = False                End If        End Function        '------------------------------------------------创建----------------------        '建一个新文件夹        '参数NewFolderDir为要创建的文件夹绝对路径        Public Sub CreateFolderB(NewFolderDir)                If IsFolderExists(NewFolderDir) Then Exit Sub                Fso.CreateFolder (NewFolderDir)        End Sub        '------------------------------------------------遍列文件------------------        Function FileItem(FolderDir)                '文件夹里的文件集合                'FolderDir 为文件夹绝对路径                If IsFolderExists(FolderDir) = False Then                        FileItem = False                        Exit Function                End If                Dim FileObj, FileerList, f                Set FileObj = Fso.GetFolder(FolderDir)                Set FileList = FileObj.Files                FileItem = FileObj.Files.Count '文件总数                For Each f In FileList                        FileItem = FileItem & "|" & f.name                Next                Set FileList = Nothing                Set FileObj = Nothing        End Function        '保证路径完整性        '成功创建或目录完整返回True,否则返回False        'strPath:目录相对路径        Public Function CheckPath(strPath)                On Error Resume Next                '创建FSO对象                Dim strCheckPath                '去掉头尾“/”                if strPath<>"" Then                        If Asc(Mid(strPath, Len(strPath), 1)) = 47 Then                                strPath = Left(strPath, Len(strPath) - 1)                        End If                        If Asc(Mid(strPath, 1, 1)) = 47 Then                                strPath = Right(strPath, Len(strPath) - 1)                        End If                Else                        CheckPath=False                        Exit Function                End if                '利用数组保存文件夹                Arr_strPath = Split(strPath, "/")                strCheckPath = Server.MapPath("/")                For i = 0 To UBound(Arr_strPath)                        If Arr_strPath(i) <> "" Then                                strCheckPath = strCheckPath & "\" & Arr_strPath(i)                                If Not IsFolderExists(strCheckPath) Then                                        '如果不存在就创建                                        CreateFolderB(strCheckPath)                                End If                        End If                Next                If Not IsFolderExists(Server.Mappath("/" & strPath)) Then                        CheckPath = False                Else                        CheckPath = True                End if        End FunctionEnd Class%>

调用测试:

VBScript code
<%        '文件生成操作开始    strFilePath = "/HTML/CCTV/"        Set FileObj  = New clsFileObj        With FileObj                '验证目录完整性                blnTemp = .CheckPath(strFilePath)                if blnTemp Then                        Response.write "创建文件夹“" & strFilePath &"“成功!
"                Else                        Response.write "创建路径出错,没有权限"                        Response.End                End if        End With        Set FileObj=Nothing%>


上一篇: asp在线裁切/剪切图片(需AspJpeg支持)
下一篇: 中医秘方
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 3380
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 300 字 | UBB代码 开启 | [img]标签 关闭