ASP in the creation of multilevel directory of the two-piece code _ Application Tips

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.