直接给大家分享一下错新站长站测试正常可以使用的代码,并且支持多级目录创建
代码一
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
使用方法:
CreateMultiFolder("/202003/tools/")
代码二、测试ok
'自动创建多极目录'code by jb51 reterryfunction createit(path)dim fsofo,cinfo,thepath,thepatharraydim i,ii,binfobinfo=falsethepath=pathset fsofo=createobject("scripting.filesystemobject")if err thenerr.clearexit functionend ifthepath=replace(thepath,"/","/")if left(thepath,1)="/" thenthepath=right(thepath,len(thepath)-1)end ifif right(thepath,1)="/" thenthepath=left(thepath,len(thepath)-1)end ifthepatharray=split(thepath,"/")for i=0 to ubound(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 function
测试代码
createit("/202004/tools/")
以上代码如果无法运行,请检查iis运行用户的权限是否有写功能。今天测试的时候默认iis7.5下是无法运行的。
下面的实现代码功能性简单,适合学习
ASP如何检测某文件夹是否存在,不存在则自动创建folder=server.mappath("/imagess") Set fso = CreateObject("Scripting.FileSystemObject") if fso.fileexists(Server.mappath(filepath)) then respnse.write("都有了还建什么建") else fso.createfolder(folder) end if Set fso = nothingDim objFSO Set objFSO = Server.CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists(Server.MapPath(SavePath))=false Then objFSO.CreateFolder(Server.MapPath(SavePath)) End Iffolder=server.mappath("/imagess") Set fso = CreateObject("Scripting.FileSystemObject") if fso.fileexists(Server.mappath(filepath)) then respnse.write("都有了还建什么建") else fso.createfolder(folder) end if Set fso = nothing
新闻热点
疑难解答