Article View: borland.public.cppbuilder.nativeapi
Article #169Re: extended file search
From: Remy Lebeau (TeamB)
Date: Mon, 30 Jun 2008 16:39
Date: Mon, 30 Jun 2008 16:39
72 lines
3000 bytes
3000 bytes
"SοΏ½ren Zimmermann" <soeren.zimmermann@sef-softec.de> wrote in message
news:4868dffe$1@newsgroups.borland.com...
> So what I need is an idea of code (or maybe some existing component)
> of how to create a list of all files matching the definitions.
The VCL has a MatchesMask() function that you can use for that, ie:
#include <Masks.hpp>
bool __fastcall IsAMatch(const AnsiString &FileName, TStrings *Masks)
{
for(int i = 0; i < Masks->Count; ++i)
{
if( MatchesMask(FileName, Masks->Strings[i]) )
return true;
}
return false;
}
void __fastcall DeleteFiles(const AnsiString &Directory, TStrings
*IncludedFiles, TStrings *ExcludedFiles)
{
AnsiString tmpDir = IncludeTrailingBackslash(Directory);
TSearchRec sr;
if( FindFirst(tmpDir + "*.*", faAnyFile, sr) == 0 )
{
try
{
do
{
if( sr.Attr & faDirectory )
DeleteFiles(tmpDir + sr.Name, IncludedFiles,
ExcludedFiles);
else if( IsAMatch(sr.Name, IncludedFiles) &&
!IsAMatch(sr.Name, ExcludedFiles) )
DeleteFile(tmpDir + sr.Name);
}
while( FindNext(sr) == 0 );
}
__finally
{
FindClose(sr);
}
}
}
{
TStringList *IncludedFiles, *ExcludedFiles;
...
IncludedFiles->Add("*.bmp");
IncludedFiles->Add("*.gif");
ExcludedFiles->Add("Default.*");
...
DeleteFiles("C:\\Some directory", IncludedFiles, ExcludedFiles);
}
> Of course I could use FindFirstFile/FindNextFile
You will have to do that anyway.
> but then I will only get a list of files matching my include files.
Only if you rely on FindFirstFile()'s pattern matching. Instead, you can
pass it "*.*" to get all files, and then match them to your search lists
manually.
Gambit
Technical Details
Message-ID:
<48690c9d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<4868dffe$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6bc3b3cc44e0a25 X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4868dffe$1@newsgroups.borland.com> Subject: Re: extended file search Date: Mon, 30 Jun 2008 09:39:44 -0700 Lines: 74 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <48690c9d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1214844061 207.178.157.90 (30 Jun 2008 09:41:01 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail