Parent page: Service Functions – System (QTP, VBScript)
Use FileSystemObject.FileExists method.
Argument should be a full path string.
When to use it? Always before trying to access the file (delete, rename, or read from).
Does file format matter? No. It could be text file, excel spreadsheet, bitmap, binary file, – anything. Just make sure you pass into both filename and extension.
Note. Always release the object you created when you no longer need it. If you don’t do that then in the long run it’ll cause you memory leakage problem.
Set FSO = CreateObject("Scripting.FileSystemObject") boolRC = FSO.FileExists(sFileName) Set FSO = Nothing 'release an object If Not boolRC Then 'do what you need to do if 'file does not exist End If