以下為兩個自寫的ASP函數,第一個函數CheckDir,用于判斷所指定的文件夾是否存在,也就是目錄是否存在;第二個函數CheckFile用于檢查指定文件是否存在在于某個目錄中。
兩個函數都是基于ASP中的FileSystemObject對象,也就是FSO,寫成函數方便以后使用。
ASP檢查目錄是否存在的函數代碼
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檢查文件是否存在的函數代碼
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
下面是其他網友的補充
'==================================================
'函數名: CheckFile
'作 用:檢查某一文件是否存在
'參 數: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檢查文件與目錄是否存在的函數代碼的文章就介紹到這了,更多相關asp文件是否存在內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- ASP如何檢測某文件夾是否存在,不存在則自動創建
- asp 判斷上傳文件中是否存在危險代碼
- asp判斷某個文件是否存在的函數