Share via


Path.Exists(String) 方法

定義

判斷指定的檔案或目錄是否存在。

public:
 static bool Exists(System::String ^ path);
public static bool Exists (string? path);
static member Exists : string -> bool
Public Shared Function Exists (path As String) As Boolean

參數

path
String

要檢查的路徑

傳回

true 如果呼叫端具有必要的許可權,且 path 包含現有檔案或目錄的名稱,則為 , false否則為 。 如果 falsepath、無效路徑或長度為零的字串,這個方法也會傳回 null。 如果呼叫端沒有足夠的許可權可讀取指定的路徑,則不會擲回任何例外狀況,而且方法會傳回 false ,而不論是否存在 path

備註

不同於 Exists(String),這個方法會 true 針對現有的非一般檔案傳回,例如管道。 如果路徑以現有連結為目標,但連結的目標不存在,則會傳 true回 。

適用於