电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:26日期: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運行用戶的權(quán)限是否有寫功能。今天測試的時候默認iis7.5下是無法運行的。

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

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

復(fù)制文件

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:\網(wǎng)站項目\photo\aspupload\07_images\")

下面是其他網(wǎng)友的補充 

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

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

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

"http://提供文件處理通用接口
Class FileSystemObject
"/*
" * 功能描述:刪除文件
" * 輸入?yún)?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)建
" * 輸入?yún)?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

 

"/*
" * 功能描述:重命名文件夾
" * 輸入?yún)?shù):GetPath——文件夾路徑
" * 輸入?yún)?shù):OldName——舊的文件夾名稱
" * 輸入?yún)?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("目錄已經(jīng)存在!!");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

 

"/*
" * 功能描述:保存當(dāng)前文件
" * 輸入?yún)?shù):GetPath——文件路徑
" * 輸入?yún)?shù):GetContent——保存的內(nèi)容
" * 輸入?yún)?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)建的詳細內(nèi)容,更多關(guān)于ASP如何檢測某文件夾是否存在的資料請關(guān)注其它相關(guān)文章!

標簽: ASP
相關(guān)文章:
主站蜘蛛池模板: 浴室柜-浴室镜厂家-YINAISI · 意大利设计师品牌 | 咿耐斯 |-浙江台州市丰源卫浴有限公司 | 高低温万能试验机-复合材料万能试验机-馥勒仪器| 长沙网站建设制作「网站优化推广」-网页设计公司-速马科技官网 | 慈溪麦田广告公司,提供慈溪广告设计。 | 北京企业宣传片拍摄_公司宣传片制作-广告短视频制作_北京宣传片拍摄公司 | 昆明网络公司|云南网络公司|昆明网站建设公司|昆明网页设计|云南网站制作|新媒体运营公司|APP开发|小程序研发|尽在昆明奥远科技有限公司 | 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | POM塑料_PBT材料「进口」聚甲醛POM杜邦原料、加纤PBT塑料报价格找利隆塑料 | 截齿|煤截齿|采煤机截齿|掘进机截齿|旋挖截齿-山东卓力截齿厂家报价 | 包装机_厂家_价格-山东包装机有限公司 | 东莞市踏板石餐饮管理有限公司_正宗桂林米粉_正宗桂林米粉加盟_桂林米粉加盟费-东莞市棒子桂林米粉 | 早报网 | 中山市派格家具有限公司【官网】 | 岩石钻裂机-液压凿岩机-劈裂机-挖改钻_湖南烈岩科技有限公司 | 泥浆在线密度计厂家-防爆数字压力表-膜盒-远传压力表厂家-江苏大亚自控设备有限公司 | 菲希尔X射线测厚仪-菲希尔库伦法测厚仪-无锡骏展仪器有限责任公司 | 玻璃瓶厂家_酱菜瓶厂家_饮料瓶厂家_酒瓶厂家_玻璃杯厂家_徐州东明玻璃制品有限公司 | 捆扎机_气动捆扎机_钢带捆扎机-沈阳海鹞气动钢带捆扎机公司 | 汽车水泵_汽车水泵厂家-瑞安市骏迪汽车配件有限公司 | 石家庄律师_石家庄刑事辩护律师_石家庄取保候审-河北万垚律师事务所 | Pos机办理_个人商户免费POS机申请-拉卡拉办理网 | 无菌检查集菌仪,微生物限度仪器-苏州长留仪器百科 | 代理记账_免费注册公司_营业执照代办_资质代办-【乐财汇】 | 杭州实验室尾气处理_实验台_实验室家具_杭州秋叶实验设备有限公司 | 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 禹城彩钢厂_钢结构板房_彩钢复合板-禹城泰瑞彩钢复合板加工厂 | 医疗仪器模块 健康一体机 多参数监护仪 智慧医疗仪器方案定制 血氧监护 心电监护 -朗锐慧康 | 奇酷教育-Python培训|UI培训|WEB大前端培训|Unity3D培训|HTML5培训|人工智能培训|JAVA开发的教育品牌 | 喷码机,激光喷码打码机,鸡蛋打码机,手持打码机,自动喷码机,一物一码防伪溯源-恒欣瑞达有限公司 | 【铜排折弯机,钢丝折弯成型机,汽车发泡钢丝折弯机,线材折弯机厂家,线材成型机,铁线折弯机】贝朗折弯机厂家_东莞市贝朗自动化设备有限公司 | ERP企业管理系统永久免费版_在线ERP系统_OA办公_云版软件官网 | 氧化锆纤维_1800度高温退火炉_1800度高温烧结炉-南京理工宇龙新材料股份有限公司 | SRRC认证_电磁兼容_EMC测试整改_FCC认证_SDOC认证-深圳市环测威检测技术有限公司 | 施工围挡-施工PVC围挡-工程围挡-深圳市旭东钢构技术开发有限公司 | 昆明化妆培训-纹绣美甲-美容美牙培训-昆明博澜培训学校 | 房屋质量检测-厂房抗震鉴定-玻璃幕墙检测-房屋安全鉴定机构 | 干粉砂浆设备-干粉砂浆生产线-干混-石膏-保温砂浆设备生产线-腻子粉设备厂家-国恒机械 | 分子蒸馏设备(短程分子蒸馏装置)_上海达丰仪器 | 大行程影像测量仪-探针型影像测量仪-增强型影像测量仪|首丰百科 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 磨煤机配件-高铬辊套-高铬衬板-立磨辊套-盐山县宏润电力设备有限公司 | 威实软件_软件定制开发_OA_OA办公系统_OA系统_办公自动化软件 |