Path.GetFileName 메서드

정의

오버로드

GetFileName(ReadOnlySpan<Char>)

읽기 전용 문자 범위로 표시되는 파일 경로의 파일 이름 및 확장명을 반환합니다.

GetFileName(String)

지정된 경로 문자열에서 파일 이름과 확장명을 반환합니다.

GetFileName(ReadOnlySpan<Char>)

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

읽기 전용 문자 범위로 표시되는 파일 경로의 파일 이름 및 확장명을 반환합니다.

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

매개 변수

path
ReadOnlySpan<Char>

파일 이름과 확장명을 가져올 경로를 포함하는 읽기 전용 범위입니다.

반환

path에서 마지막 디렉터리 구분 문자 뒤의 문자입니다.

설명

반환된 읽기 전용 범위에는 의 마지막 구분 기호 path뒤에 있는 경로의 문자가 포함됩니다. 의 path 마지막 문자가 볼륨 또는 디렉터리 구분 기호 문자이면 메서드는 를 반환합니다 ReadOnlySpan<T>.Empty. 구분 기호 문자가 없으면 path 메서드는 를 반환합니다 path.

추가 정보

적용 대상

GetFileName(String)

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

지정된 경로 문자열에서 파일 이름과 확장명을 반환합니다.

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

매개 변수

path
String

파일 이름과 확장명을 가져올 경로 문자열입니다.

반환

path에서 마지막 디렉터리 구분 문자 뒤의 문자입니다. path의 마지막 문자가 디렉터리나 볼륨 구분 문자이면 이 메서드는 Empty을(를) 반환합니다. path이(가) null이면 이 메서드는 null을(를) 반환합니다.

예외

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

예제

다음 예제에서는 Windows 기반 데스크톱 플랫폼에서 메서드의 GetFileName 동작을 보여 줍니다.

String^ fileName = "C:\\mydir\\myfile.ext";
String^ path = "C:\\mydir\\";
String^ result;
result = Path::GetFileName( fileName );
Console::WriteLine( "GetFileName('{0}') returns '{1}'", fileName, result );
result = Path::GetFileName( path );
Console::WriteLine( "GetFileName('{0}') returns '{1}'", path, result );

// This code produces output similar to the following:
//
// GetFileName('C:\mydir\myfile.ext') returns 'myfile.ext'
// GetFileName('C:\mydir\') returns ''
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;

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

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

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

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

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

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

설명

반환된 값은 null 파일 경로가 인 경우 입니다 null.

파일 이름의 시작을 확인하는 데 사용되는 구분 기호 문자는 및 AltDirectorySeparatorChar입니다DirectorySeparatorChar.

는 Unix의 법적 파일 이름이기 때문에 \ Unix 기반 플랫폼에서 실행하면 C:\mydir\myfile.ext와 같은 Windows 기반 경로에서 파일 이름을 올바르게 반환할 수 없지만 GetFileName Windows 기반 플랫폼에서 실행하면 /tmp/myfile.ext와 같은 Unix 기반 경로에서 파일 이름을 올바르게 반환할 수 있으므로 Unix 기반 및 Windows 기반 플랫폼에서 메서드의 GetFileName 동작이 엄격하게 동일하지 않습니다. GetFileName

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

추가 정보

적용 대상