' See if the file exists in the program directory.
If File.Exists("TextFile1.txt") Then
Console.WriteLine("The file exists.")
' Check a file in the C volume.
Dim exists As Boolean = File.Exists("C:\lost.txt")
End ModuleThe file exists.
Discussion. File.Exists internally accesses the disk. This causes an IO read. Sometimes it is better to simply try to read a file, as with StreamReader.
Then We could catch exceptions if the file is not found. This has fewer steps.
Also Exception handling is faster in many cases than disk reads. Therefore, skipping File.Exists and just trying to read files may be better.
Tip In some situations, File.Exists is still useful. It may prevent an incorrect state in memory.
A summary. File.Exists returns True, if a file exists. And it returns False if one does not. It is used within an If-statement conditional, and it may be stored in a Boolean field.