Path.IsPathFullyQualified Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a value that indicates whether a file path is fully qualified.
Overloads
IsPathFullyQualified(ReadOnlySpan<Char>) |
Returns a value that indicates whether the file path represented by the specified character span is fixed to a specific drive or UNC path. |
IsPathFullyQualified(String) |
Returns a value that indicates whether the specified file path is fixed to a specific drive or UNC path. |
Remarks
The overloads of the IsPathFullyQualified
method handle paths that use both the DirectorySeparatorChar and the AltDirectorySeparatorChar characters. It does not perform any validation on the path that is passed to it as an argument. As a result, URIs are interpreted as relative paths and return false
.
There is a difference between a fully qualified path (as indicated by the IsPathFullyQualified
method) and a rooted path (as indicated by the IsPathRooted method). A fully qualified path or absolute path always defines an exact path from a particular drive or device to a target file or directory, and does not depend on the current drive or current directory. For example, on Windows systems, C:/users/user1/documents/reports/2019/january/highlights.pdf defines an absolute path from the root of the C: drive to the target file, highlights.pdf. A rooted path specifies either a starting drive or root directory, but depends on either the current directory (if it is rooted by a specified drive) or the current drive (if it is rooted by the root directory). The following example illustrates the difference between fully qualified paths and rooted paths.
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>)
- Source:
- Path.cs
- Source:
- Path.cs
- Source:
- Path.cs
Returns a value that indicates whether the file path represented by the specified character span is fixed to a specific drive or UNC path.
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
Parameters
- path
- ReadOnlySpan<Char>
A file path.
Returns
true
if the path is fixed to a specific drive or UNC path; false
if the path is relative to the current drive or working directory.
See also
Applies to
IsPathFullyQualified(String)
- Source:
- Path.cs
- Source:
- Path.cs
- Source:
- Path.cs
Returns a value that indicates whether the specified file path is fixed to a specific drive or UNC path.
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
Parameters
- path
- String
A file path.
Returns
true
if the path is fixed to a specific drive or UNC path; false
if the path is relative to the current drive or working directory.
Exceptions
path
is null
.
Remarks
This method handles paths that use the alternate directory separator. It's a frequent mistake to assume that rooted paths (IsPathRooted(String)) aren't relative. For example, "C:a" is drive relative, that is, it's resolved against the current directory for C: (rooted, but relative). "C:\a" is rooted and not relative, that is, the current directory isn't used to modify the path.