2014-01-08 1 views

답변

8

사용 Path.GetFileName() 경로없이 파일 이름을 얻을 수 있습니다 :

cboLanden.DataSource = Directory.EnumerateFiles(path, "*.txt") 
           .Select(Path.GetFileName) 
           .ToList(); 
+0

오류 '경로' 'System.IO.Path'와 'System.Windows.Shapes.Path'Path.GetFileName에 오류 사이의 모호한 기준은? 나는 using.windows.shape을 추가했다. – Maxim

+1

@ user3173605'System.IO.Path.GetFileName()'과 같은 정규화 된 이름을 사용하십시오 –

+0

답장을 보내 주셔서 감사합니다! – Ahmad

0

간단한 그냥이

foreach (string file in files) 
{ 
    Path.GetFileNameWithoutExtension(file); 
} 

를 사용

또한
string path = AppDomain.CurrentDomain.BaseDirectory; 
string[] filePaths = Directory.GetFiles(path, "*.txt"); 
foreach (string file in filePaths) 
{ 
    cboLanden.Items.Add(Path.GetFileName(file)); 
} 

것은 당신의 콤보 상자 데이터 소스로 파일을 사용 고려 파일에 파일 이름이있는 경우 c:\coolpic.jpg 는 확장하지 않고 단지 coolpic를 반환합니다

관련 문제