VBScript » FileSystemObject » FileExists

Version: 2.0

Syntax:
object.FileExists(file)

Lets us check whether a specified file exists. Returns True if the file does exist and False otherwise.

Note that if the file that you are checking for isn't in the current directory, you must supply the complete path.

Examples

Code:
<%
dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CreateTextFile "c:\somefile.txt", True
If filesys.FileExists("c:\somefile.txt") Then
   filesys.DeleteFile "c:\somefile.txt"
   Response.Write("File deleted")
End If
%>
Output:
"File deleted"
Explanation:

In this example the FileExists method is used to check for a specific file before deleting it.