Path.IsPathFullyQualified 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个值,该值指示文件路径是否完全限定。
重载
| 名称 | 说明 |
|---|---|
| IsPathFullyQualified(String) |
返回一个值,该值指示指定的文件路径是固定到特定驱动器还是 UNC 路径。 |
| IsPathFullyQualified(ReadOnlySpan<Char>) |
返回一个值,该值指示指定的字符范围所表示的文件路径是固定到特定驱动器还是 UNC 路径。 |
注解
使用和字符的方法句柄路径DirectorySeparatorChar的IsPathFullyQualifiedAltDirectorySeparatorChar重载。 它不会对作为参数传递给它的路径执行任何验证。 因此,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(String)
返回一个值,该值指示指定的文件路径是固定到特定驱动器还是 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 如果路径相对于当前驱动器或工作目录,则为 。
例外
path 是 null。
注解
此方法处理使用备用目录分隔符的路径。 假设根路径(IsPathRooted(String))不是相对路径,这是一个频繁的错误。 例如,“C:a”是相对于驱动器的,也就是说,它针对 C: 的当前目录解析(根目录,但相对目录)。 “C:\a”是根目录而不是相对目录,即当前目录不用于修改路径。
另请参阅
适用于
IsPathFullyQualified(ReadOnlySpan<Char>)
返回一个值,该值指示指定的字符范围所表示的文件路径是固定到特定驱动器还是 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 如果路径相对于当前驱动器或工作目录,则为 。