Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Verify if file exist with VB script

Tags:

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"

like image 241
yael Avatar asked Jun 13 '10 07:06

yael


People also ask

How will you find out if a file exist using VB net?

Exists FunctionUse the File. Exists Function, which returns a Boolean true if the file is found on the disk.

How can I tell if a text file exists?

To check if a file exists, you pass the file path to the exists() function from the os. path standard library. If the file exists, the exists() function returns True . Otherwise, it returns False .

How do I view a VBScript file?

You can open and edit VBS files using any text editor, such as Notepad++ (Windows), Apple TextEdit (Mac), or GitHub Atom.

What is the condition to check whether file exist or not?

While checking if a file exists, the most commonly used file operators are -e and -f. The '-e' option is used to check whether a file exists regardless of the type, while the '-f' option is used to return true value only if the file is a regular file (not a directory or a device).


1 Answers

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() 
like image 64
Sarfraz Avatar answered Sep 22 '22 20:09

Sarfraz