Path.IsPathFullyQualified 方法

定義

傳回值,指出檔案路徑是否為完整路徑。

多載

IsPathFullyQualified(ReadOnlySpan<Char>)

傳回值,指出指定字元範圍所表示的檔案路徑是否固定在特定的磁碟機或 UNC 路徑。

IsPathFullyQualified(String)

傳回值,指出指定的檔案路徑是否固定在特定磁碟機或 UNC 路徑。

備註

方法的多 IsPathFullyQualified 載會處理使用 DirectorySeparatorCharAltDirectorySeparatorChar 字元的路徑。 它不會對傳遞至該路徑做為自變數的路徑執行任何驗證。 因此,URI 會解譯為相對路徑並傳回 false

完整路徑 (之間的差異,如方法) 和根路徑 (,如 IsPathFullyQualified 方法) 所示 IsPathRooted完整路徑絕對路徑一律會定義特定磁碟驅動器或裝置到目標檔案或目錄的確切路徑,而且不相依於目前的磁碟驅動器或目前目錄。 例如,在 Windows 系統上, C:/users/user1/documents/reports/2019/january/highlights.pdf 定義從 C: 磁碟驅動器根目錄到目標檔案的絕對路徑, highlights.pdf根路徑會指定起始磁碟驅動器或根目錄,但視目前目錄 (是否由指定的磁碟驅動器根目錄) ,或者如果目前磁碟驅動器是由根目錄) ,則 (。 下列範例說明完整路徑與根路徑之間的差異。

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string relative1 = "C:Documents"; 
        ShowPathInfo(relative1);

        string relative2 = "/Documents";
        ShowPathInfo(relative2);

        string absolute = "C:/Documents";
        ShowPathInfo(absolute);
    }

    private static void ShowPathInfo(string path)
    {
        Console.WriteLine($"Path: {path}");
        Console.WriteLine($"   Rooted: {Path.IsPathRooted(path)}");
        Console.WriteLine($"   Fully qualified: {Path.IsPathFullyQualified(path)}");
        Console.WriteLine($"   Full path: {Path.GetFullPath(path)}");
        Console.WriteLine();
    }
}
// The example displays the following output when run on a Windows system:
//    Path: C:Documents
//        Rooted: True
//        Fully qualified: False
//        Full path: c:\Users\user1\Documents\projects\path\ispathrooted\Documents
//
//    Path: /Documents
//       Rooted: True
//       Fully qualified: False
//       Full path: c:\Documents
//
//    Path: C:/Documents
//       Rooted: True
//       Fully qualified: True
//       Full path: C:\Documents
Imports System.IO

Module Program
    Public Sub Main()
        Dim relative1 As String = "C:Documents" 
        ShowPathInfo(relative1)

        Dim relative2 As String = "C:Documents" 
        ShowPathInfo(relative2)

        Dim absolute As String = "C:/Documents"
        ShowPathInfo(absolute)
    End Sub

    Private Sub ShowPathInfo(filepath As String)
        Console.WriteLine($"Path: {filepath}")
        Console.WriteLine($"   Rooted: {Path.IsPathRooted(filepath)}")
        Console.WriteLine($"   Fully qualified: {Path.IsPathFullyQualified(filepath)}")
        Console.WriteLine($"   Full path: {Path.GetFullPath(filepath)}")
        Console.WriteLine()
    End Sub
End Module
' The example displays the following output when run on a Windows system:
'    Path: C:Documents
'        Rooted: True
'        Fully qualified: False
'        Full path: c:\Users\user1\Documents\projects\path\ispathrooted\Documents
'
'    Path: /Documents
'       Rooted: True
'       Fully qualified: False
'       Full path: c:\Documents
'
'    Path: C:/Documents
'       Rooted: True
'       Fully qualified: True
'       Full path: C:\Documents

IsPathFullyQualified(ReadOnlySpan<Char>)

來源:
Path.cs
來源:
Path.cs
來源:
Path.cs

傳回值,指出指定字元範圍所表示的檔案路徑是否固定在特定的磁碟機或 UNC 路徑。

public:
 static bool IsPathFullyQualified(ReadOnlySpan<char> path);
public static bool IsPathFullyQualified (ReadOnlySpan<char> path);
static member IsPathFullyQualified : ReadOnlySpan<char> -> bool
Public Shared Function IsPathFullyQualified (path As ReadOnlySpan(Of Char)) As Boolean

參數

path
ReadOnlySpan<Char>

檔案路徑。

傳回

如果路徑固定在特定的磁碟機或 UNC 路徑,則為 true;如果路徑相對於目前的磁碟機或工作目錄,則為 false

另請參閱

適用於

IsPathFullyQualified(String)

來源:
Path.cs
來源:
Path.cs
來源:
Path.cs

傳回值,指出指定的檔案路徑是否固定在特定磁碟機或 UNC 路徑。

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

參數

path
String

檔案路徑。

傳回

如果路徑固定在特定的磁碟機或 UNC 路徑,則為 true;如果路徑相對於目前的磁碟機或工作目錄,則為 false

例外狀況

pathnull

備註

這個方法會處理使用替代目錄分隔符的路徑。 假設根路徑 () IsPathRooted(String) 不是相對的,這是常見的錯誤。 例如,“C:a” 是相對磁碟驅動器,也就是說,它會針對 C: (根目錄解析,但相對) 。 “C:\a” 是根目錄,而不是相對的,也就是說,目前目錄不會用來修改路徑。

另請參閱

適用於