|
DoyongID 님이 쓰신 글 :
: *.bmp;*.pcx;*.jpg 를 하위폴더까지 검색해서 파일 리스트를 얻어오는 프로그램을 짜려고 하는데요..
:
: 위의 확장자를 한꺼번에 검사하는 방법은 없을까요?
:
: 지금은 bmp파일을 다 찾고 나서 다시 처음부터 pcx파일 찾고, 다시 처음부터 jpg 찾고... 그런 식으로 하고 있습니다..
#include<Masks.hpp>
bool MatchesFilenameFilters(const AnsiString filename, const TStrings* filters)
{
for(int i=0; i<filters->Count ;i++){
if(MatchesMask(filename,filters->Strings[i])){
return true;
}
}
return false;
}
//---------------------------------------------------------------------------
void FindFiles(const AnsiString path, const TStrings* filters, bool recursive)
{
TSearchRec sr;
int iAttributes = ~(faSysFile|faVolumeID); // 찾을 파일 속성 지정
if(FindFirst(path+".\\*.*", iAttributes, sr)==0){
do{
if(sr.Attr & faDirectory){
if(recursive && sr.Name[1]!='.') FindFiles(path+".\\"+sr.Name,filters,recursive);
}else{
if(MatchesFilenameFilters(sr.Name,filters)) ; //파일필터에 맞음
else ; //파일필터에 맞지 않음
}
} while(FindNext(sr)==0);
FindClose(sr);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//Edit1에 찾을 디렉터리를, ListBox1에 파일필터들을 한줄에 하나씩, CheckBox1에 하위디렉터리검색여부를 지정한 후
FindFiles(Edit1->Text,ListBox1->Items,CheckBox1->Checked);
}
|