Click here to Skip to main content
Click here to Skip to main content

Multi-threaded file finder class

, 29 Mar 2002
Rate this:
Please Sign up or sign in to vote.
A class that searches a directory tree for files using a worker thread, keeping the main app. usable.


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;
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:



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


United States United States
No Biography provided

Comments and Discussions

GeneralSuggestion PinmemberNiklas Lindquist22-Jun-09 9:31 
GeneralMulti-threaded DLL PinmemberJRaiden29-Jan-06 14:39 
GeneralAnother at CodeProject PinmemberDaniel Madden1-Apr-02 20:00 
GeneralOne minor point PinmemberTim Smith31-Mar-02 3:48 
GeneralRe: One minor point Pinmembersultan_of_6string31-Mar-02 6:27 
GeneralRe: One minor point PinmemberTodd Smith31-Mar-02 8:29 
GeneralRe: One minor point Pinmembersultan_of_6string31-Mar-02 8:58 
GeneralRe: One minor point PinmemberJase Jennings5-Apr-02 1:15 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150326.1 | Last Updated 30 Mar 2002
Article Copyright 2002 by sultan_of_6string
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid