Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags more
Archives
Today
Total
관리 메뉴

개발자로 살아남기

[C#] 파일 경로에서 파일 이름, 확장자를 제외한 파일 이름, 파일 확장자 추출하기 본문

프로그래밍/C#

[C#] 파일 경로에서 파일 이름, 확장자를 제외한 파일 이름, 파일 확장자 추출하기

UnaUna 2023. 10. 29. 23:29

파일 경로에서 파일 이름, 확장자를 제외한 파일 이름, 파일 확장자 추출하기

1. 파일 경로에서 파일 이름 추출하기 - Path.GetFileName

var filePath = "D:\\test\\abcd.png";
var fileName = Path.GetFileName(filePath);
System.Console.WriteLine(fileName);

결과

abcd.png

2. 파일 경로에서 파일 확장자 추출하기 - Path.GetFileExtension

var filePath = "D:\\test\\abcd.png";
var extension = Path.GetExtension(filePath);
System.Console.WriteLine(extension);

결과

.png

3. 파일 경로에서 확장자를 제외한 파일 이름 추출하기 - Path.GetFileNameWithoutExtension

var filePath = "D:\\test\\abcd.png";
var fileName = Path.GetFileName(filePath);
System.Console.WriteLine(fileName);

결과

abcd