2011-12-15 2 views
0

가능한 중복 :
GetFiles with multiple extentionsDirectory.getfiles()

나는 여러 필터 예를 들어, 사용하려는 :에 .JPG, .MP3를 이러한 형식의 파일의 문자열 배열을 검색합니다. 그러나 불행히도 Directory.getfiles()는이 기능을 효율적으로 제공하지 않습니다.

이 질문이 여기에 여러 번 요청되었습니다 알고 있지만 난 그냥

public string[] getFiles(string SourceFolder, string Filter, 
System.IO.SearchOption searchOption) 
{ 
// ArrayList will hold all file names 
ArrayList alFiles = new ArrayList(); 

// Create an array of filter string 
string[] MultipleFilters = Filter.Split('|'); 

// for each filter find mathing file names 
foreach (string FileFilter in MultipleFilters) 
{ 
    // add found file names to array list 
    alFiles.AddRange(Directory.GetFiles(SourceFolder, FileFilter, searchOption)); 
} 

// returns string array of relevant file names 
return (string[])alFiles.ToArray(typeof(string)); 
} 

내가 알고 싶은이 문제를 다루는 위해 다음과 같은 기능을 제공합니다 http://www.beansoftware.com/ASP.NET-FAQ/Multiple-Filters-Directory.GetFiles-Method.aspx

에서 기사를 발견 이 방법은 효율적입니다. 예 : C : \ 드라이브가 지정되면이 방법은 전체 드라이브를 검색합니까? 누군가 나에게이 방법으로 검색 하위 폴더를 추가하는 방법을 제안 할 수 명시 적으로

답변

0

당신은 또한 당신이 원하는 파일과 조합 결과

를 얻기 위해 전체 결과에 LINQ 쿼리를 실행 할 수 있습니다
관련 문제