程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> asp中創建多級目錄的兩段代碼

asp中創建多級目錄的兩段代碼

編輯:關於ASP編程
復制代碼 代碼如下:
        '==============================
        '創建多級目錄,可以創建不存在的根目錄
        '參數:要創建的目錄名稱,可以是多級
        '創建目錄的根目錄從當前目錄開始
        '''調用舉例
        ''Call CreateMultiFolder("/upload/jumbot/myphoto/")
        '==============================

        Function CreateMultiFolder(ByVal CFolder)
                Dim objFSO, PhCreateFolder, CreateFolderArray, CreateFolder
                Dim i, ii, CreateFolderSub, PhCreateFolderSub, BlInfo
                BlInfo = False
                CreateFolder = CFolder
                On Error Resume Next
                Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
                If Err Then
                        Err.Clear()
                        Exit Function
                End If
                If Right(CreateFolder, 1) = "/" Then
                        CreateFolder = Left(CreateFolder, Len(CreateFolder) -1)
                End If
                CreateFolderArray = Split(CreateFolder, "/")
                For i = 0 To UBound(CreateFolderArray)
                        CreateFolderSub = ""
                        For ii = 0 To i
                                CreateFolderSub = CreateFolderSub & CreateFolderArray(ii) & "/"
                        Next
                        PhCreateFolderSub = Server.MapPath(CreateFolderSub)
                        If Not objFSO.FolderExists(PhCreateFolderSub) Then
                                objFSO.CreateFolder(PhCreateFolderSub)
                        End If
                Next
                If Err Then
                        Err.Clear()
                Else
                        BlInfo = True
                End If
                CreateMultiFolder = BlInfo
        End Function

上面的是循環
下面的是正則
復制代碼 代碼如下:
        '==============================
        ''創建文件目錄(多層)
        ''使用正則
        '==============================

        Function Create_N_Folder(save, ByVal Path)
                Dim Fso
                Set Fso = Server.CreateObject("Scripting.FileSystemObject")
                If Not Fso.FolderExists(Path) Then
                        Dim regEx
                        Set regEx = New RegExp
                        regEx.Pattern = "^(.*)\\([^\\]*)$"
                        regEx.Global = False
                        regEx.IgnoreCase = True
                        save = save & regEx.Replace(Path, "$2") & "|"
                        Path = regEx.Replace(Path, "$1")
                        If Create_N_Folder(save, Path) Then Create_N_Folder = True
                        Set regEx = Nothing
                Else
                        If save = "|" Then
                                Create_N_Folder = True
                        Else
                                Dim Temp
                                Temp = Mid(save, 2, Len(save) - 2)
                                If InStrRev(Temp, "|") = 0 Then
                                        save = "|"
                                        Path = Path & "\" & Temp
                                Else
                                        Dim Folder
                                        Folder = Mid(Temp, InStrRev(Temp, "|") + 1)
                                        save = "|" & Mid(Temp, 1, InStrRev(Temp, "|") - 1) & "|"
                                        Path = Path & "\" & Folder
                                End If
                                Fso.CreateFolder Path
                                If Create_N_Folder(save, Path) Then Create_N_Folder = True
                        End If
                End If
                Set Fso = Nothing
        End Function
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved