Click here to Skip to main content
Licence 
First Posted 29 Mar 2002
Views 60,257
Bookmarked 31 times

Multi-threaded file finder class

By | 29 Mar 2002 | Article
A class that searches a directory tree for files using a worker thread, keeping the main app. usable.

Introduction

The CFileFinder class searches a directory tree for files and adds their full paths to a CStringList object (my own class, included with the source). It is built in 'pure Windows'--no MFC--with just a few classes of my own. The main feature of CFileFinder is that it uses a worker thread to find the files. File finding can take quite a while, so this lets the main program remains responsive to the user. By means of a callback function, the main program can continuously update a file list. Furthermore, CFileFinder can be halted at any time by calling CFileFinder::Stop().

NOTE: CFileFinder and its requisite classes use UNICODE. Porting them to ANSI for Win 95/98/Me is a no-brainer, but that's something I'm not going to bother doing. If you still use such 3rd-rate OSs (no offense) then you can go ahead and do so, or use the Microsoft Layer for Unicode that will do the job for you.

Quick Guide:

First, create the global CFileFinder and CStringList (that receives the file list) objects:

CFileFinder g_filefinder;<br>CStringList g_files;

Call CFileFinder::Start to begin the search. The function returns immediately:

g_filefinder.Start(&g_files, strRootfolder, strFilter,
    TRUE /* search sub-folders */, FinderCallback, 0);

Note that the path to the root folder must end in a backslash.

The callback function notifies the application of the last found file, whether the operation is complete (in which case there is no last found file), whether there was an error and a user specified UINT:

void CALLBACK FileFinderProgressProc(CFileFinder* pFileFinder, 
    PCWSTR pszFile, BOOL bDone, BOOL bError, UINT uUserData);

The CFileFinder::Stop function can be called at any time to halt the search:

g_finder.Stop();

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

sultan_of_6string



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralSuggestion PinmemberNiklas Lindquist8:31 22 Jun '09  
GeneralMulti-threaded DLL PinmemberJRaiden13:39 29 Jan '06  
GeneralAnother at CodeProject PinmemberDaniel Madden19:00 1 Apr '02  
GeneralOne minor point PinmemberTim Smith2:48 31 Mar '02  
GeneralRe: One minor point Pinmembersultan_of_6string5:27 31 Mar '02  
GeneralRe: One minor point PinmemberTodd Smith7:29 31 Mar '02  
GeneralRe: One minor point Pinmembersultan_of_6string7:58 31 Mar '02  
GeneralRe: One minor point PinmemberJase Jennings0:15 5 Apr '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 30 Mar 2002
Article Copyright 2002 by sultan_of_6string
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid