How to: Determine if a File Exists in Visual Basic

You can use the FileExists method to determine whether or not a specified file exists.

If the application does not have sufficient permissions to read the specified file, the FileExists method returns False regardless of the existence of path; the method does not throw an exception.


Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To determine if a file exists

  • Use the My.Computer.FileSystem.FileExists method, supplying the path, to determine whether or not the specified file exists. The following example checks to see whether or not the file Check.txt exists and supplies the information in a message box.

    If My.Computer.FileSystem.FileExists("c://Check.txt") Then
        MsgBox("File found.")
        MsgBox("File not found.")
    End If

Community Additions