How to Verify if file exist with VB script

yael picture yael · Jun 13, 2010 · Viewed 120.5k times · Source

How do I verify via VBScript if the file conf exist under Program Files (i.e. C:\Program Files\conf)?

For example if it exists, then msgBox "File exists"
If not, then msgbox "File doesn't exist"

Answer

Sarfraz picture Sarfraz · Jun 13, 2010

There is no built-in functionality in VBS for that, however, you can use the FileSystemObject FileExists function for that :

Option Explicit
DIM fso    
Set fso = CreateObject("Scripting.FileSystemObject")

If (fso.FileExists("C:\Program Files\conf")) Then
  WScript.Echo("File exists!")
  WScript.Quit()
Else
  WScript.Echo("File does not exist!")
End If

WScript.Quit()