Copy Code code as follows:
'==============================
' Create a multilevel directory, you can create a non-existent root directory
' Parameter: The name of the directory to create, which can be multilevel
' Create the root directory of the directory starting from the current directory
"" "Call example
' 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
The top is a loop.
The following is the regular
Copy Code code as follows:
'==============================
"Create a file directory (multi-tier)
' Use regular
'==============================
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, "$") & "|"
Path = Regex.Replace (path, "$")
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