🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

find .exe's

#998
From: mataus
Date: Tue, 30 Oct 2007 20:54
57 lines
2398 bytes
Hi all,

I need code to find all .exe file on a disk.  I use FindFirstFile / 
FindNextFile and it works but it seems slow.  When i run code its time is 
long (1 min 30 secs for ~2500 files on T60 thinkpad ).  However, if i use 
command line cmd->dir *.exe /s - time is fast (10 secs for ~2500 on T60). 
Can anyone help me make this fast?

My code is:

void TForm1::RecursiveSearch(const AnsiString &p_sPath)
{
   bool bNext;
   HANDLE hFileSearching;
   WIN32_FIND_DATA fdFindFileData;

   AnsiString sPath = p_sPath;

   if (!sPath.IsPathDelimiter(sPath.Length()))
      sPath = AnsiString(sPath + "\\");

   sPath = AnsiString(sPath + "*");

   hFileSearching = FindFirstFile(sPath .c_str(), &fdFindFileData);

   // If the handle is valid, process it
   if (bNext = (hFileSearching != INVALID_HANDLE_VALUE))
   {
      AnsiString szFile;
      do
      {
         // Call self if it finds directory
         if ((FILE_ATTRIBUTE_DIRECTORY & fdFindFileData.dwFileAttributes) &&
             strcmp(fdFindFileData.cFileName,".") && 
strcmp(fdFindFileData.cFileName,".."))
         {
            RecursiveSearch(ExtractFilePath(sPath) + 
fdFindFileData.cFileName);
         }

         szFile = (AnsiString)fdFindFileData.cFileName;
         if (ExtractFileExt(szFile)==".exe")
         {
               Memo1->Lines->Add(szFile);
         }
         // Process next file...
         bNext = FindNextFile(hFileSearching, &fdFindFileData);

         Application->ProcessMessages();
     }
     while (bNext);
   }
   FindClose(hFileSearching);
}


thanks - mataus 
Technical Details
Message-ID: <4727891b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,52a2861022dfbb0b,start
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "mataus" <mataus@gmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: find .exe's
Date: Tue, 30 Oct 2007 20:54:11 -0000
Lines: 59
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.3959
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133
NNTP-Posting-Host: 78.148.33.87
Message-ID: <4727891b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1193773339 78.148.33.87 (30 Oct 2007 12:42:19 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail