Path.IsPathFullyQualified 方法

定義

回傳一個值,表示檔案路徑是否完全合格。

多載

名稱 Description
IsPathFullyQualified(ReadOnlySpan<Char>)

傳回值,這個值表示指定的字元範圍所代表的檔案路徑是否固定至特定磁碟驅動器或 UNC 路徑。

IsPathFullyQualified(String)

傳回值,這個值表示指定的檔案路徑是否固定至特定磁碟驅動器或 UNC 路徑。

備註

方法的 IsPathFullyQualified 超載處理同時使用 和 DirectorySeparatorCharAltDirectorySeparatorChar 路徑。 它不會對作為參數傳遞給它的路徑進行任何驗證。 因此,URI被解釋為相對路徑並回傳 false

完全限定路徑(依方法指示)與根路徑(依方法指示IsPathFullyQualifiedIsPathRooted)之間存在差異。 完全限定路徑絕對路徑總是定義從特定磁碟或裝置到目標檔案或目錄的精確路徑,且不依賴於目前的磁碟或目錄。 例如,在Windows系統中,C:/users/user1/documents/reports/2019/january/highlights.pdf 定義了從 C: 磁碟根節點到目標檔案的絕對路徑,highlights.pdf根路徑指定起始磁碟或根目錄,但取決於目前的目錄(若被指定磁碟 root 或是 root 磁碟)。 以下範例說明了完全限定路徑與根路徑之間的差異。

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
來源:
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>

檔案路徑。

傳回

true 如果路徑固定在特定的硬碟或 UNC 路徑上; false 如果路徑是相對於目前的磁碟機或工作目錄。

另請參閱

適用於

IsPathFullyQualified(String)

來源:
Path.cs
來源:
Path.cs
來源:
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

檔案路徑。

傳回

true 如果路徑固定在特定的硬碟或 UNC 路徑上; false 如果路徑是相對於目前的磁碟機或工作目錄。

例外狀況

pathnull

備註

此方法處理使用替代目錄分隔符的路徑。 常常錯誤地認為根路徑()IsPathRooted(String)不是相對的。 例如,「C:a」是磁碟的相對,也就是說,它會根據目前 C: 的目錄(有根但相對)解析。 「C:\a」是根目錄,不是相對的,也就是說,目前的目錄不會用來修改路徑。

另請參閱

適用於