FileExists Method (My.Computer.FileSystem Object)
TOC
Collapse the table of content
Expand the table of content

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

file

String. Name and path of the file. Required.

Returns True if the file exists; otherwise this method returns False.

The following condition may create an exception:

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.

The following table lists an example of a task involving the My.Computer.FileSystem.FileExists method.

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

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

The following permission may be necessary:

Permission

Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.

Show:
© 2016 Microsoft