문자열로 경로 이름 설정 -
string myPath = "D:\\new\\quiz.txt";
이제 GetFileName() 메서드를 사용하여 파일 이름을 가져옵니다. -
Path.GetFileName(myPath)
다음은 완전한 코드입니다 -
예시
using System;
using System.IO;
namespace Demo {
class Program {
static void Main(string[] args) {
string myPath = "D:\\new\\quiz.txt";
// get extension
Console.WriteLine("Extension: "+Path.GetExtension(myPath));
// get path
Console.WriteLine("File Path: "+Path.GetFileName(myPath));
}
}
} 출력
Extension: .txt File Path: D:\new\quiz.txt