ASP檢查文件與目錄是否存在的函數(shù)代碼
更新時間:2020年09月14日 23:54:18 投稿:mdxy-dxy
第一個函數(shù)CheckDir,用于判斷所指定的文件夾是否存在,也就是目錄是否存在;第二個函數(shù)CheckFile用于檢查指定文件是否存在在于某個目錄中
以下為兩個自寫的ASP函數(shù),第一個函數(shù)CheckDir,用于判斷所指定的文件夾是否存在,也就是目錄是否存在;第二個函數(shù)CheckFile用于檢查指定文件是否存在在于某個目錄中。
兩個函數(shù)都是基于ASP中的FileSystemObject對象,也就是FSO,寫成函數(shù)方便以后使用。
ASP檢查目錄是否存在的函數(shù)代碼
Function CheckDir(Byval FolderPath)
dim fso
folderpath=Server.MapPath(".")&"\"&folderpath
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(FolderPath) then
'存在
CheckDir = True
Else
'不存在
CheckDir = False
End if
Set fso = nothing
End Function
或
Function isExistFolder(Byval folderDir) on error resume next If objFso.FolderExists(server.MapPath(folderDir)) Then isExistFolder=True Else isExistFolder=False if err then err.clear:isExistFolder=False End Function
ASP檢查文件是否存在的函數(shù)代碼
Function CheckFile(Byval FilePath) '檢查某一文件是否存在
Dim fso
Filepath=Server.MapPath(FilePath)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(FilePath) then
'存在
CheckFile = True
Else
'不存在
CheckFile = False
End if
Set fso = nothing
End Function
或
Function isExistFile(Byval fileDir) on error resume next If (objFso.FileExists(server.MapPath(fileDir))) Then isExistFile=True Else isExistFile=False if err then err.clear:isExistFile=False End Function
下面是其他網(wǎng)友的補充
'==================================================
'函數(shù)名: CheckFile
'作 用:檢查某一文件是否存在
'參 數(shù):FileName ------ 文件地址 如:/swf/1.swf
'返回值:False ---- True
'==================================================
Public Function CheckFile(FileName)
On Error Resume Next
Dim FsoObj
Set FsoObj = Server.CreateObject("Scripting.FileSystemObject")
If Not FsoObj.FileExists(Server.MapPath(FileName)) Then
CheckFile = False
Exit Function
End If
CheckFile = True:Set FsoObj = Nothing
End Function
到此這篇關(guān)于ASP檢查文件與目錄是否存在的函數(shù)代碼的文章就介紹到這了,更多相關(guān)asp文件是否存在內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
服務器XMLHTTP(Server XMLHTTP in ASP)基礎知識
幾年很流行 Ajax,而 Ajax 的本質(zhì)就是 XMLHttpRequest,是客戶端 XMLHttpRequest 對象的使用。2010-08-08
將ACCESS轉(zhuǎn)化成SQL2000要注意的問題
很多朋友想用SQL2000數(shù)據(jù)庫的編程方法,但是卻又苦于自己是學ACCESS的,對SQL只是一點點的了解而已,這里我給大家提供以下參考---將ACCESS轉(zhuǎn)化成SQL2000的方法和注意事項2007-03-03

