Export (0) Print
Expand All

FileSystem.FileExists Method

Returns True if the specified file exists.

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static bool FileExists(
	string file
)

Parameters

file
Type: System.String

Name and path of the file.

Return Value

Type: System.Boolean
Returns True if the file exists; otherwise this method returns False.

ExceptionCondition
ArgumentException

The name of the file ends with a backslash (\).

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.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft