แก้ไข

แชร์ผ่าน


FileSystem.FileExists(String) Method

Definition

Returns True if the specified file exists.

public:
 static bool FileExists(System::String ^ file);
public static bool FileExists (string file);
static member FileExists : string -> bool
Public Shared Function FileExists (file As String) As Boolean

Parameters

file
String

Name and path of the file.

Returns

Returns True if the file exists; otherwise this method returns False. This method also returns False if the parameter represents the path of a directory rather than a file.

Exceptions

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

Examples

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

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.

Applies to