🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11498

Re: Search directories for a file mask problem...

#11498
From: Remy Lebeau (TeamB)
Date: Fri, 06 Feb 2004 06:09
49 lines
2565 bytes
"Martin C" <martinc@aol.com> wrote in message
news:402301fc@newsgroups.borland.com...

> I have a problem that the search does not cover all the
> directory subdirectories...so can someone help me please
> by telling me what exactly I am missing here...

It doesn't work because you are passing your file mask to FindFirst()
directly, thus it is going to skip any folders that do not match the mask.
In order to search all folders, you need to use "*.*" as the FindFirst()
mask instead, and then compare each individual file against your actual
mask.

You are also stopping your searching prematurely by having a 'return'
statement in the middle of your loop.  After the first subfolder is found,
no more subfolders on the same level will be searched.

Try this code instead:

    bool __fastcall TForm1::SearchForFile(AnsiString Folder, const
AnsiString &MaskToFind)
    {
        TSearchRec sr;
        bool returnedval = false;

        Folder = IncludeTrailingBackslash(Folder);
        if( FindFirst(Folder + "*.*", faAnyFile, sr) == 0 )
        {
            do
            {
                if( (sr.Name != ".")  && (sr.Name != "..") )
                {
                    if( sr.Attr & faDirectory )
                        returnedval = SearchForFile(Folder + sr.Name,
MaskToFind);
                    else
                        returnedval = MatchesMask(sr.Name, MaskToFind);
                }
            }
            while( (!returnedval) && (FindNext(sr) == 0) );
            FindClose(sr);
        }

        return returnedval;
    }


Gambit
Technical Details
Message-ID: <40232de8$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <402301fc@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,b023f6f11f20de80
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-05 22:09:44 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <402301fc@newsgroups.borland.com>
Subject: Re: Search directories for a file mask problem...
Date: Thu, 5 Feb 2004 22:09:30 -0800
Lines: 51
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.138.253
Message-ID: <40232de8$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1076047336 67.22.138.253 (5 Feb 2004 22:02:16 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail