Home Blogs Library Forums Support Advertise
VB Script
 
A Basic Tutorial
File System Programing
 
VBScript and MS Excel
VBScript and MS Access
 
VBScript and MS Word
VBScript and MS Powerpoint
 
Windows Registry Programing
 
Windows Administration
 
Active Directory Programing
 
Miscellaneous Functions
 
You are here...
Home >Vb Script - Home

VBScript - Check Whether a File Exists or Not

We can check whether a file is existsing in the file system or not, using a function 'FileExists' in the file system Object. This function takes an argument which is the name of the file with the complete path and will return a boolean value. 'True' means the file Exists; 'False' means the file doesn't Exist. The syntax of the 'FileExists' function is as follows

Syntax:
FileExists(filename)

'filename': Here the argument filename is the name of the file with complete path.

The following demonstrates how to check for a file.

Check Whether a File Exists or Not

Dim ObjFso
Dim StrFileName
Dim BoolResult

StrFileName = "C:\TestFile.txt"
Set ObjFso = CreateObject("Scripting.FileSystemObject")
BoolResult = ObjFso.FileExists(StrFileName)

If BoolResult = True Then
   WScript.Echo("The file exists.")
Else
   WScript.Echo("The file doesn't exists!!")
End If