Path.IsPathRooted 메서드

정의

파일 경로에 루트가 포함되는지 여부를 나타내는 값을 반환합니다.

오버로드

IsPathRooted(ReadOnlySpan<Char>)

파일 경로를 나타내는 지정된 문자 범위가 루트를 포함하는지 여부를 나타내는 값을 반환합니다.

IsPathRooted(String)

지정된 경로 문자열에 루트가 포함되는지 여부를 나타내는 값을 반환합니다.

설명

루트 경로는 특정 드라이브 또는 UNC 경로에 고정된 파일 경로입니다. 현재 드라이브 또는 작업 디렉터리를 기준으로 하는 경로와 대조됩니다. 예를 들어 Windows 시스템에서 루트 경로는 백슬래시(예: "\Documents") 또는 드라이브 문자 및 콜론(예: "C:Documents")으로 시작합니다.

루트 경로는 절대 경로(즉, 정규화됨) 또는 상대 경로일 수 있습니다. 절대 루트 경로는 드라이브의 루트에서 특정 디렉터리로의 정규화된 경로입니다. 상대 루트 경로는 드라이브를 지정하지만 해당 정규화된 경로는 현재 디렉터리에 대해 확인됩니다. 다음 예제에서 차이점을 보여 줍니다.

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

IsPathRooted(ReadOnlySpan<Char>)

Source:
Path.Unix.cs
Source:
Path.Unix.cs
Source:
Path.Unix.cs

파일 경로를 나타내는 지정된 문자 범위가 루트를 포함하는지 여부를 나타내는 값을 반환합니다.

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

매개 변수

path
ReadOnlySpan<Char>

테스트할 경로입니다.

반환

path에 루트가 포함되어 있으면 true이고, 그렇지 않으면 false입니다.

추가 정보

적용 대상

IsPathRooted(String)

Source:
Path.Unix.cs
Source:
Path.Unix.cs
Source:
Path.Unix.cs

지정된 경로 문자열에 루트가 포함되는지 여부를 나타내는 값을 반환합니다.

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

매개 변수

path
String

테스트할 경로입니다.

반환

path에 루트가 포함되어 있으면 true이고, 그렇지 않으면 false입니다.

예외

2.1 이전의 .NET Framework 및 .NET Core 버전: path 에 정의된 잘못된 문자가 하나 이상 포함되어 있습니다GetInvalidPathChars().

예제

다음 예제에서는 메서드를 IsPathRooted 사용하여 세 개의 문자열을 테스트하는 방법을 보여 줍니다.

String^ fileName = "C:\\mydir\\myfile.ext";
String^ UncPath = "\\\\myPc\\mydir\\myfile";
String^ relativePath = "mydir\\sudir\\";
bool result;
result = Path::IsPathRooted( fileName );
Console::WriteLine( "IsPathRooted('{0}') returns {1}", fileName, result.ToString() );
result = Path::IsPathRooted( UncPath );
Console::WriteLine( "IsPathRooted('{0}') returns {1}", UncPath, result.ToString() );
result = Path::IsPathRooted( relativePath );
Console::WriteLine( "IsPathRooted('{0}') returns {1}", relativePath, result.ToString() );

// This code produces output similar to the following:
//
// IsPathRooted('C:\mydir\myfile.ext') returns True
// IsPathRooted('\\myPc\mydir\myfile') returns True
// IsPathRooted('mydir\sudir\') returns False
string fileName = @"C:\mydir\myfile.ext";
string UncPath = @"\\myPc\mydir\myfile";
string relativePath = @"mydir\sudir\";
bool result;

result = Path.IsPathRooted(fileName);
Console.WriteLine("IsPathRooted('{0}') returns {1}",
    fileName, result);

result = Path.IsPathRooted(UncPath);
Console.WriteLine("IsPathRooted('{0}') returns {1}",
    UncPath, result);

result = Path.IsPathRooted(relativePath);
Console.WriteLine("IsPathRooted('{0}') returns {1}",
    relativePath, result);

// This code produces output similar to the following:
//
// IsPathRooted('C:\mydir\myfile.ext') returns True
// IsPathRooted('\\myPc\mydir\myfile') returns True
// IsPathRooted('mydir\sudir\') returns False
Dim fileName As String = "C:\mydir\myfile.ext"
Dim UncPath As String = "\\myPc\mydir\myfile"
Dim relativePath As String = "mydir\sudir\"
Dim result As Boolean

result = Path.IsPathRooted(fileName)
Console.WriteLine("IsPathRooted('{0}') returns {1}", fileName, result)

result = Path.IsPathRooted(UncPath)
Console.WriteLine("IsPathRooted('{0}') returns {1}", UncPath, result)

result = Path.IsPathRooted(relativePath)
Console.WriteLine("IsPathRooted('{0}') returns {1}", relativePath, result)

' This code produces output similar to the following:
'
' IsPathRooted('C:\mydir\myfile.ext') returns True
' IsPathRooted('\\myPc\mydir\myfile') returns True
' IsPathRooted('mydir\sudir\') returns False

설명

메서드는 IsPathRooted 첫 번째 문자가 "\"와 같은 디렉터리 구분 기호 문자이거나 경로가 드라이브 문자 및 콜론(:))으로 시작하는 경우 를 반환 true 합니다. 예를 들어 "\\MyDir\MyFile.txt", "C:\MyDir" 또는 "C:MyDir"와 같은 문자열에 대해 path 를 반환 true 합니다. "MyDir"과 같은 문자열에 대해 path 를 반환 false 합니다.

이 메서드는 경로 또는 파일 이름이 있는지 확인하지 않습니다.

일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.

추가 정보

적용 대상