다음을 통해 공유


Path.GetPathRoot 메서드

정의

오버로드

Name Description
GetPathRoot(String)

지정된 문자열에 포함된 경로에서 루트 디렉터리 정보를 가져옵니다.

GetPathRoot(ReadOnlySpan<Char>)

지정된 문자 범위에 포함된 경로에서 루트 디렉터리 정보를 가져옵니다.

GetPathRoot(String)

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

지정된 문자열에 포함된 경로에서 루트 디렉터리 정보를 가져옵니다.

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

매개 변수

path
String

루트 디렉터리 정보를 가져올 경로를 포함하는 문자열입니다.

반품

루트가 있는 경우의 path 루트 디렉터리입니다.

-또는-

루트 디렉터리 정보가 없으면

-또는-

null이거나 null 사실상 비어 있는 경우 path

예외

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

-또는-

.NET Framework만: Empty 에 전달되었습니다 path.

예제

다음 예제에서는 메서드를 사용하는 방법을 보여 줍니다 GetPathRoot .

string path = @"\mydir\";
string fileName = "myfile.ext";
string fullPath = @"C:\mydir\myfile.ext";
string pathRoot;

pathRoot = Path.GetPathRoot(path);
Console.WriteLine("GetPathRoot('{0}') returns '{1}'",
    path, pathRoot);

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

pathRoot = Path.GetPathRoot(fullPath);
Console.WriteLine("GetPathRoot('{0}') returns '{1}'",
    fullPath, pathRoot);

// This code produces output similar to the following:
//
// GetPathRoot('\mydir\') returns '\'
// GetPathRoot('myfile.ext') returns ''
// GetPathRoot('C:\mydir\myfile.ext') returns 'C:\'
Dim pathname As String = "\mydir\"
Dim fileName As String = "myfile.ext"
Dim fullPath As String = "C:\mydir\myfile.ext"
Dim pathnameRoot As String

pathnameRoot = Path.GetPathRoot(pathname)
Console.WriteLine("GetPathRoot('{0}') returns '{1}'", pathname, pathnameRoot)

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

pathnameRoot = Path.GetPathRoot(fullPath)
Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fullPath, pathnameRoot)

' This code produces output similar to the following:
'
' GetPathRoot('\mydir\') returns '\'
' GetPathRoot('myfile.ext') returns ''
' GetPathRoot('C:\mydir\myfile.ext') returns 'C:\'

설명

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

이 메서드는 디렉터리 구분 기호를 정규화합니다.

문자열은 다음과 같은 경우 "효과적으로 비어 있습니다".

  • Windows에서 이 문자열을 호출 IsEmpty 하면 반환 true되거나 모든 문자가 공백(' ')입니다.
  • Unix에서 이 문자열을 호출 IsNullOrEmpty 하면 반환됩니다 true.

이 메서드에서 반환된 문자열에 대한 가능한 패턴은 다음과 같습니다.

  • null (path null 또는 빈 문자열)입니다.

  • 빈 문자열(path 현재 드라이브 또는 볼륨의 상대 경로 지정)입니다.

  • "/"(Unix: path 현재 드라이브에 절대 경로를 지정했습니다.)

  • "X:"(Windows: path 드라이브의 상대 경로를 지정했습니다. 여기서 X 는 드라이브 또는 볼륨 문자를 나타냅니다).

  • "X:\"(Windows: path 지정된 드라이브에서 절대 경로를 지정).

  • "\\ComputerName\SharedFolder"(Windows: UNC 경로).

  • "\\?\C:"(Windows: .NET 버전 및 .NET Framework 4.6.2 이상 버전에서 지원되는 DOS 디바이스 경로).

Windows의 파일 경로에 대한 자세한 내용은 Windows 시스템의 파일 경로 형식을 참조하세요. 일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.

추가 정보

적용 대상

GetPathRoot(ReadOnlySpan<Char>)

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

지정된 문자 범위에 포함된 경로에서 루트 디렉터리 정보를 가져옵니다.

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

매개 변수

path
ReadOnlySpan<Char>

루트 디렉터리 정보를 가져올 경로를 포함하는 문자의 읽기 전용 범위입니다.

반품

의 루트 디렉터리를 포함하는 읽기 전용 문자 범위입니다 path.

설명

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

문자열 오버로드와 달리 이 메서드는 디렉터리 구분 기호를 정규화하지 않습니다.

A ReadOnlySpan<System.Char> 는 다음과 같은 경우 "효과적으로 비어 있습니다".

이 메서드에서 반환하는 읽기 전용 문자 범위에 대한 가능한 패턴은 다음과 같습니다.

  • ReadOnlySpan<T>.Empty (path 입니다 ReadOnlySpan<T>.Empty.

  • ReadOnlySpan<T>.Empty (path 현재 드라이브 또는 볼륨의 상대 경로를 지정).

  • "/"(Unix: path 현재 드라이브에 절대 경로를 지정했습니다.)

  • "X:"(Windows: path 드라이브의 상대 경로를 지정했습니다. 여기서 X 는 드라이브 또는 볼륨 문자를 나타냅니다).

  • "X:\"(Windows: path 지정된 드라이브에서 절대 경로를 지정).

  • "\\ComputerName\SharedFolder"(Windows: UNC 경로).

  • "\\?\C:"(Windows: .NET 버전 및 .NET Framework 4.6.2 이상 버전에서 지원되는 DOS 디바이스 경로).

Windows의 파일 경로에 대한 자세한 내용은 Windows 시스템의 파일 경로 형식을 참조하세요. 일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.

추가 정보

적용 대상