2010-08-02 2 views
0

가 나는 경로가 전체 파일 이름을 얻을 * .wsdl 파일

고마워요!

+0

IDE에서 탐색기를 찾으십니까? 어떤 버전입니까? – leppie

답변

2

뭔가 :

var files = Directory.GetFiles("C:\\Users\\Web References", "*.wsdl", SearchOption.AllDirectories); 

이 파일의 컬렉션을 반환합니다 - 디렉토리에 하나 이상의 WSDL 파일이있을 수 있습니다. 첫 번째를 타고 :

string path = @"C:\Users\Web References"; 
string[] files = Directory.GetFiles(path, "*.wsdl"); 

foreach (string filePath in files) { 
    string filename = Path.GetFileName(filePath); // e.g. myFile.wsdl 
} 
0

먼저, 당신은 그것을 찾을 수있다 :

var files = Directory.GetFiles(path, "*.wsdl"); 

지금 filespath 모든 WSDL 파일에 대한 전체 경로 (있는 경우)를 포함합니다. 이 같은

+0

그리고 나서'Path.GetFileName (string)'을 사용하여 파일 이름을 가져올 수 있습니다. (substring-indexOf magic * shudders *를 사용하지 않아도됩니다. – Bobby

0
// find files by filter 
var result = Directory.GetFiles("C:\\Users\\Web References\\", "*.wsdl"); 
//if you have only one file 
return System.IO.Path.GetFileName(result[0]); // "my.wsdl" 
1

아무도 그것을 언급되지 않은 것을보고 :

var wsdlFile = files.FirstOrDefault(); 
0

또는 linq를 사용하여

var files = from f in Directory.GetFiles((@"C:\Users\Web References") 
    where f.EndsWith(".wsdl") 
    select f; 

foreach (var file in files) 
    ...