Tuesday, 11 November 2014

Determine if a File Exists in Visual Basic

Determine if a File Exists in Visual Basic

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://Sample.txt") Then
        MsgBox("File found.")
    Else
        MsgBox("File not found.")
    End If