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"
Exists FunctionUse the File. Exists Function, which returns a Boolean true if the file is found on the disk.
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 .
You can open and edit VBS files using any text editor, such as Notepad++ (Windows), Apple TextEdit (Mac), or GitHub Atom.
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).
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With