ASP檢查文件與目錄是否存在的函數(shù)代碼
以下為兩個自寫的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
到此這篇關于ASP檢查文件與目錄是否存在的函數(shù)代碼的文章就介紹到這了,更多相關asp文件是否存在內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
asp中獲取當前頁面的地址與參數(shù)的函數(shù)代碼
asp中獲取當前頁面的地址與參數(shù)的函數(shù)代碼,經(jīng)常需要用得到,特整理下,方便需要的朋友。2011-01-01
asp下取得客戶端IP地址函數(shù) 轉(zhuǎn)換IP地址函數(shù)
asp下取得客戶端IP地址函數(shù) 轉(zhuǎn)換IP地址函數(shù)...2007-08-08
.Net core 的熱插拔機制的深入探索及卸載問題求救指南
這篇文章主要介紹了.Net core 的熱插拔機制的深入探索及卸載問題求救指南,本文給大家啊介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11

