QTP General Function to check/verify that some file exits on the given path or not.

Below is the QTP function which can be used in any general functional library to check/verify that a file exists or not.

1: Function CheckFile(FilePath)
2: 'Create the File System Object
3:  Set objFS = CreateObject("Scripting.FileSystemObject")
4: 'Ensure that the file exists
5:  If Not objFS.FileExists(FilePath) Then
6:     ' issue a fail if the file wasn't found
7:     Reporter.ReportEvent micFail, "Read File", "Unable to read  file, file not found: " & FilePath
8:     ' file wasn't found, so exit  test
9:     ExitTest
10: End If
11: End Function

Explanation:-
1. We pass the fine name as a string to the function.
3. Then we are creating the file system object, “objFS”.
5. Now to ensure that the file exists on the file system, we use if conditional statement.
7. If the File name is not found on the file system, Fail is issued to the test with specified message.
8. After fail is issued, exit the test.