My.Computer.FileSystem.FileExists Method
Returns a Boolean indicating whether the specified file exists.
' Usage
Dim value As Boolean = My.Computer.FileSystem.FileExists(file)
' Declaration
Public Function FileExists( _
ByVal file As String _
) As Boolean
Parameters
- file
String. Name and path of the file. Required.
Return Value
Returns True if the file exists; otherwise this method returns False.
Exceptions
The following condition may create an exception:
- The name of the file ends with a backslash (\) (ArgumentException).
Remarks
If the application does not have sufficient permissions to read the specified file, the FileExists method returns False, regardless of the existence of the path; the method does not throw an exception.
Tasks
The following table lists an example of a task involving the My.Computer.FileSystem.FileExists method.
To |
See |
---|---|
Determine if a file exists |
Example
This 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.")
Else
MsgBox("File not found.")
End If
Requirements
Namespace:Microsoft.VisualBasic.MyServices
Class:FileSystemProxy (provides access to FileSystem)
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
Project type |
Available |
---|---|
Windows Application |
Yes |
Class Library |
Yes |
Console Application |
Yes |
Windows Control Library |
Yes |
Web Control Library |
Yes |
Windows Service |
Yes |
Web Site |
Yes |
Permissions
The following permission may be necessary:
Permission |
Description |
---|---|
Controls the ability to access files and folders. Associated enumeration: Unrestricted. |
For more information, see Code Access Security and Requesting Permissions.
See Also
Tasks
How to: Determine if a Directory Exists in Visual Basic
Walkthrough: Manipulating Files and Directories in Visual Basic
Reference
Other Resources
Creating, Deleting, and Moving Files and Directories in Visual Basic