I will share with you the code that can be used normally when testing the wrong new webmaster website, and it supports multi-level directory creation
Code 1
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 FunctionHow to use:
CreateMultiFolder("/202003/tools/")
Code 2, test ok
'Automatically create multipole directory'code by jb51 reterryfunction createit(path)dim fsofo,cinfo,thepatharraydim i,ii,binfobinfo=falsethepath=pathset fsofo=createobject("scripting.filesystemobject")if err thenerr.clearexit functionend ifthepath=replace(thepath,"/","/")if left(thepath,1)="/" thepath=right(thepath,len(thepath)-1)end ifif right(thepath,1)="/" thenthepath=left(thepath,len(thepath)-1)end ifthepatharray=split(thepath,"/")for i=0 to ubund(thepatharray)createfoldersub1=createfoldersub1&thepatharray(i)&"/"createfoldersub=server.mappath(createfoldersub1)if not fsofo.folderexists(createfoldersub) thenfsofo.createfolder(createfoldersub)end ifnextif err thenerr.clearelsebinfo=trueend ifcreateit=binfoend functionTest code
createit("/202004/tools/")
If the above code cannot be run, please check whether the permissions of the iis run user have a write function. During the test today, the default iis7.5 cannot be run.
The following implementation code is simple and suitable for learning
How to detect whether a folder exists? If it does not exist, it will automatically create folder=server.mappath("/imagess")Set fso = CreateObject("Scripting.FileSystemObject")if fso.fileexists(Server.mappath(filepath)) thenrespnse.write("What else can be built after all")elsefso.createfolder(folder)end ifSet fso = nothingDim objFSOSet objFSO = Server.CreateObject("Scripting.FileSystemObject")If objFSO.FolderExists(Server.MapPath(SavePath))=false ThenobjFSO.CreateFolder(Server.MapPath(SavePath))End Ifffolder=server.mappath("/imagess")Set fso = CreateObject("Scripting.FileSystemObject")if fso.fileexists(Server.mappath(filepath)) thenrespnse.write("What else can be built after all")elsefso.createfolder(folder)end ifSet fso = nothing