There is a method in FSO called CreateFolder, but this method can only create a new folder if its upper-level folder exists, so I wrote a function that automatically creates multi-level folders and generates static pages, etc. It is very convenient to use.
Function:
'--------------------------------
' Automatically create specified multi-level folders
'strPath is the absolute path
' Please retain copyright for citations
' 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
Calling method:
MyPath = "C:abc"
If AutoCreateFolder(MyPath) Then
Response.Write "Folder created successfully"
Else
Response.Write "Failed to create folder"
End If