Check File Existence with FileStystemObject
In many cases we need to check if a particular file exists on the server or not.
This simple function returns true or false based on the file existence. Just pass
a valid file name to the function.
<%
Option Explicit
Dim FileName
FileName = "MyFile.asp"
FileName = Server.MapPath("/Files/" & FileName)
If IsFileExists(FileName)
= True Then
Response.Write "File exists"
Else
Response.Write "File does not exists"
End If
' **********************************
' Function to check file Existance
' **********************************
Function IsFileExists(byVal FileName)
If FileName =
"" Then
IsFileExists = False
Exit Function
End If
Dim objFSO
Set objFSO =
Server.CreateObject("Scripting.FileSystemObject")
If (objFSO.FileExists(
FileName ) = True Then
IsFileExists = True
Else
IsFileExists = False
End If
Set objFSO =
Nothing
End Function
%>
|
Have Questions? Discuss this topic in Dev
Forum
|