2012-05-28 3 views

답변

5

당신은 Path 클래스의 방법 GetFileName를 사용할 수 있습니다

String path = "D:\Users\admin\Documents\file.txt"; 
string name = System.IO.Path.GetFileName(path); 
2

Path.GetFileName는 당신이 필요로 돌아갑니다.

string fileName = @"D:\Users\admin\Documents\file.txt"; 
string result; 

result = Path.GetFileName(fileName); 

result는 "file.txt를"입니다.

2

당신이 파일 확장자를 사용

System.IO.Path.GetFileNameWithoutExtension(path); 
2

사용 Path.GetFileName method없이 원하는 경우 파일 확장자를 사용

System.IO.Path.GetFileName(path); 

로하려면 다음 aleroot가 말했듯이

string fileName = Path.GetFileName(path); 
2

, 당신이 원하는 System.IO.Path 클래스를 사용하십시오. 사용 방법 :

string strFullFilePath = "D:\Users\admin\Documents\file.txt"; 
string strFileNameOnly = System.IO.Path.GetFileName(strFullFilePath); 

이 정보가 도움이되기를 바랍니다.

관련 문제