Path.GetPathRoot 메서드

정의

오버로드

GetPathRoot(String)

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

GetPathRoot(ReadOnlySpan<Char>)

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

GetPathRoot(String)

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의 루트 디렉터리입니다.

또는

path이(가) 루트 디렉터리 정보를 포함하지 않은 경우 Empty입니다.

또는

path이(가) null이거나 실질적으로 비어있으면 null입니다.

예외

2.1 이전의 .NET Framework 및 .NET Core 버전: 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:\'
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 Core 1.1 이상 버전 및 .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

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

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의 루트 디렉터리를 포함하는 읽기 전용 문자 범위입니다.

설명

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

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

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

  • Windows에서 이 문자 범위에서 를 호출 ReadOnlySpan<T>.IsEmpty 하면 가 반환 true되거나 모든 문자가 공백(' ')입니다.
  • Unix에서 이 문자 범위에서 를 호출 ReadOnlySpan<T>.IsEmpty 하면 가 반환됩니다 true.

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

  • 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 Core 1.1 이상 버전 및 .NET Framework 4.6.2 이상 버전에서 지원되는 DOS 디바이스 경로).

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

추가 정보

적용 대상