There is a method in the FSO that is createfolder, but this method can only create a new folder in the presence of a folder above it, so I wrote a function to create a multilevel folder automatically, which is very convenient for the generation of static pages.
Function:
' --------------------------------
' Automatically create a specified multilevel folder
' strpath is an absolute path
' Reference please retain the copyright
' 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
' Create
Objfso.createfolder (strTmpPath)
End If
Next
Set objFSO = Nothing
If ERR = 0 Then
Autocreatefolder = True
Else
Autocreatefolder = False
End If
End Function
Call Method:
MyPath = "C:\a\b\c\"
If Autocreatefolder (MyPath) Then
Response.Write "Create folder succeeded"
Else
Response.Write "Create folder Failed"
End If