|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
How to: Determine if a File Exists in Visual Basic
You can use theto 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.
The options available in dialog boxes, and the names and locations of menu commands you see, might differ from what is described in Help, depending on your active settings or edition. This Help page was written with General Development Settings in mind. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see.
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.