ASP如何检测某文件夹是否存在,不存在则自动建设

直接给各人分享一下剧本之家测试正常可以利用的代码,而且支持多级目次建设

代码一

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) = "https://www.jb51.net/" Then CreateFolder = Left(CreateFolder, Len(CreateFolder) -1) End If CreateFolderArray = Split(CreateFolder, "https://www.jb51.net/") For i = 0 To UBound(CreateFolderArray) CreateFolderSub = "" For ii = 0 To i CreateFolderSub = CreateFolderSub & CreateFolderArray(ii) & "https://www.jb51.net/" 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 reterry function createit(path) dim fsofo,cinfo,thepath,thepatharray dim i,ii,binfo binfo=false thepath=path set fsofo=createobject("scripting.filesystemobject") if err then err.clear exit function end if thepath=replace(thepath,"\","https://www.jb51.net/") if left(thepath,1)="https://www.jb51.net/" then thepath=right(thepath,len(thepath)-1) end if if right(thepath,1)="https://www.jb51.net/" then thepath=left(thepath,len(thepath)-1) end if thepatharray=split(thepath,"https://www.jb51.net/") for i=0 to ubound(thepatharray) createfoldersub1=createfoldersub1&thepatharray(i)&"https://www.jb51.net/" createfoldersub=server.mappath(createfoldersub1) if not fsofo.folderexists(createfoldersub) then fsofo.createfolder(createfoldersub) end if next if err then err.clear else binfo=true end if createit=binfo end 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 = nothing Dim objFSO  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")  If objFSO.FolderExists(Server.MapPath(SavePath))=false Then  objFSO.CreateFolder(Server.MapPath(SavePath))  End If 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 = nothing  

都不完善,我想楼主的意思是建设无极深度目次吧,给个我写的: 

'建设新文件夹(答允无级建设)1:35 2005-1-31 Public Function CreateFolder(FolderPath) Dim sObjFSO Dim arrFolder Dim i Set sObjFSO = Server.CreateObject("Scripting.FileSystemObject") FolderPath = Replace(FolderPath,"\","https://www.jb51.net/") arrFolder = Split(FolderPath,"https://www.jb51.net/") On Error Resume Next For i = 0 To UBound(arrFolder) If i > 0 Then arrFolder(i) = arrFolder(i-1) & "https://www.jb51.net/" & arrFolder(i) If Not sObjFSO.FolderExists(arrFolder(i)) Then sObjFSO.CreateFolder(arrFolder(i)) End If Next CreateFolder = True If Err.number <> 0 Then CreateFolder = False Err.Clear End If End Function

建设文件夹

dim fso,SavePath SavePath=server.MapPath(".\"&imagefile&"\"&username&"\"&specialname&"") set fso = server.CreateObject("scripting.filesystemobject") if fso.FolderExists(SavePath)=false then fso.createfolder(SavePath) end if set fso=nothing

删除文件夹

dim fso,SavePath SavePath=server.MapPath(".\"&imagefile&"\"&username&"\"&specialname&"") set fso = server.CreateObject("scripting.filesystemobject") if fso.FolderExists(SavePath)=true then fso.deletefolder(SavePath) end if set fso=nothing

复制文件

dim fso set fso=server.CreateObject("scripting.filesystemobject") sub copyfiles(path,path2) set mycopy=fso.getfile(path) response.flush() mycopy.copy path2 response.write("<b>installed success !&nbsp;&nbsp;</b>"&path2&"<br>") response.Flush() end sub call copyfiles(Server.MapPath("../无标题2.bmp"),"D:\网站项目\photo\aspupload\07_images\")

下面是其他网友的增补 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsdfdp.html