国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

ASP如何檢測某文件夾是否存在,不存在則自動創(chuàng)建

瀏覽:25日期:2022-06-05 08:06:36

直接給大家分享一下測試正常可以使用的代碼,并且支持多級目錄創(chuàng)建

代碼一

 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

"自動創(chuàng)建多極目錄
"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,"\","/")
if left(thepath,1)="/" then
thepath=right(thepath,len(thepath)-1)
end if
if right(thepath,1)="/" then
thepath=left(thepath,len(thepath)-1)
end if
thepatharray=split(thepath,"/")
for i=0 to ubound(thepatharray)
createfoldersub1=createfoldersub1&thepatharray(i)&"/"
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下是無法運行的。

下面的實現(xiàn)代碼功能性簡單,適合學習

ASP如何檢測某文件夾是否存在,不存在則自動創(chuàng)建

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  

都不完善,我想樓主的意思是創(chuàng)建無極深度目錄吧,給個我寫的: 

"創(chuàng)建新文件夾(允許無級創(chuàng)建)1:35 2005-1-31 

Public Function CreateFolder(FolderPath) 
Dim sObjFSO 
Dim arrFolder 
Dim i 

Set sObjFSO = Server.CreateObject("Scripting.FileSystemObject") 
FolderPath = Replace(FolderPath,"\","/") 
arrFolder = Split(FolderPath,"/") 
On Error Resume Next 

For i = 0 To UBound(arrFolder) 
If i > 0 Then arrFolder(i) = arrFolder(i-1) & "/" & 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 

創(chuàng)建文件夾

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\")

下面是其他網友的補充 

Public Function CheckAndCreateFolder(FolderName)
  fldr = Server.Mappath(FolderName)
  Set fso = CreateObject("Scripting.FileSystemObject")
  If Not fso.FolderExists(fldr) Then
   fso.CreateFolder(fldr)
  End If
  Set fso = Nothing
End Function

 檢查文件夾是否存在,不存在則創(chuàng)建文件夾,該函數(shù)無返回值。

例:CheckAndCreateFolder("ASP")

檢查當前目錄下是否存在ASP文件夾,不存在則創(chuàng)建文件夾ASP ,缺點是不支持多級目錄創(chuàng)建。

 asp關于fso函數(shù),文件與文件夾的相關操作用得到

"http://提供文件處理通用接口
Class FileSystemObject
"/*
" * 功能描述:刪除文件
" * 輸入參數(shù):FileName——文件相對路徑
"*/
Public Function DelFile(FileName)
 Dim getPath
 getPath="/"
 SET Fso=Server.CreateObject("Scripting.FileSystemObject")
 getPath=Replace(getPath&FileName,"http://","/")
 if Fso.FileExists(Server.MapPath(getPath))=True then
   Fso.DeleteFile Server.mappath(getPath)
 End if
 Set Fso=Nothing
End Function

 

"/*
" * 功能描述:判斷路徑是否存在,如不存在則創(chuàng)建
" * 輸入參數(shù):SaveFilePath——相對路徑,如:/UploadFiles/NewsFiles
"*/
Public Function CreatePath(SaveFilePath)
 Dim DeclarePath,FileObj,FilePath
 DeclarePath="/"
 
 Set FileObj=Server.CreateObject("Scripting.FileSystemObject") 
 For Each FilePath in split(SaveFilePath,"/") 
   DeclarePath=Replace(DeclarePath&FilePath&"/","http://","/") 
   if FileObj.FolderExists(Server.MapPath(DeclarePath))=false then 
     FileObj.CreateFolder(Server.MapPath(DeclarePath))"創(chuàng)建文件夾
   end if
 Next 
 Set FileObj=nothing
 CreatePath=DeclarePath
End Function

 

"/*
" * 功能描述:重命名文件夾
" * 輸入參數(shù):GetPath——文件夾路徑
" * 輸入參數(shù):OldName——舊的文件夾名稱
" * 輸入參數(shù):NewName——新的文件夾名稱
"*/
Public Function RenFolder(GetPath,OldName,NewName) 
 Dim Fso
 if OldName="" or NewName="" then
   exit Function
 else
   if OldName=NewName then exit Function
 end if
 SET Fso=Server.CreateObject("Scripting.FileSystemObject")
 if Fso.FolderExists(Server.MapPath(GetPath&NewName)) then
   response.write"<script language=javascript>alert("目錄已經存在!!");this.history.go(-1);</script>"
   response.end()
 end if
 "http://舊的文件夾不存在,則創(chuàng)建
 if Not Fso.FolderExists(Server.MapPath(GetPath&OldName)) Then
   CreatePath(GetPath&OldName)
 End if
 
 Fso.MoveFolder Server.MapPath(GetPath&OldName),Server.MapPath(GetPath&NewName)
 set Fso=nothing
 "response.redirect request.ServerVariables("HTTP_REFERER")
End Function

 

"/*
" * 功能描述:保存當前文件
" * 輸入參數(shù):GetPath——文件路徑
" * 輸入參數(shù):GetContent——保存的內容
" * 輸入參數(shù):GetFile——保存的文件名
"*/
Public Function SaveEditFile(GetPath,GetContent,GetFile)
 if GetContent="" or GetFile="" then exit Function
 SET Fso=Server.CreateObject("Scripting.FileSystemObject")
 set CF=Fso.CreateTextFile(Server.mappath(GetPath&GetFile),true)
 CF.write GetContent
 CF.Close
 set CF=nothing
 set Fso=nothing
 "response.redirect request.ServerVariables("HTTP_REFERER")
End Function

End Class

以上就是ASP如何檢測某文件夾是否存在,不存在則自動創(chuàng)建的詳細內容,更多關于ASP如何檢測某文件夾是否存在的資料請關注其它相關文章!

標簽: ASP
相關文章:
主站蜘蛛池模板: 精品极品三级久久久久 | 在线第一页 | 视频在线一区二区 | 黄色在线不卡 | 亚洲精品久久久久网站 | 真人一级一级特黄高清毛片 | 日产日韩亚洲欧美综合搜索 | 日产国产精品亚洲系列 | 久久黄色影片 | 手机在线国产精品 | 午夜毛片网站 | 大片刺激免费播放视频 | 91精品国产91久久久久青草 | 久久色精品| 欧美在线视频精品 | 国产一区二区三区免费 | 日本一区二区三区高清在线观看 | 泰国情欲片寂寞的寡妇在线观看 | 亚洲精品h| 精品欧美成人高清在线观看2021 | 成人男女啪啪免费观看网站 | 久久综合久久自在自线精品自 | 日韩三级黄色 | 成人在线免费观看网站 | 日韩精品亚洲人成在线观看 | 一级特黄特黄毛片欧美的 | 国产成人精品一区二区免费视频 | 在线播放一级片 | 五月色婷婷综合开心网4438 | 在线毛片观看 | 久久毛片免费看 | 97视频在线观看免费播放 | 国产成人精品亚洲日本语音 | 国产美女主播一级成人毛片 | 亚洲综合精品一二三区在线 | 久香草视频在线观看 | 国产欧美成人一区二区三区 | 成人在线手机视频 | 美女黄视频在线观看 | 狠狠色丁香久久婷婷综 | 日韩在线国产 |