Click here to Skip to main content
12,406,649 members (50,776 online)
Click here to Skip to main content
Add your own
alternative version

Stats

144.2K views
1.1K downloads
29 bookmarked
Posted

Easy to use file finding dialog

, 19 Mar 2001
Rate this:
Please Sign up or sign in to vote.
An easy to use multi-threaded dialog class that will search disks for files. Similar to Explorer's "Find Files of Folders" tool.
<!-- Link to demo file download -->
  • Download demo project - 21 Kb
  • <!-- Article image -->

    Sample Image - FindFileSearching.gif

    <!-- Add the rest of your HTML here -->

    Introduction

    Because we couldn't find out how to use the Windows "Find Files or Folders" dialog in our own app, and we needed to be able to retrieve a list of the files that were found in our app (which I don't think the Windows dialog even allows you to do), we wrote our own.

    CFindFileDlg is a simple dialog class that you can use to search hard drives (or floppy, or network, or CDROM drives) for files. It supports wildcards, and recursive folder searching, allows you to end the search after the first file is found, comes standard with a cancel button, simple animated icon and is fully multi-threaded.

    Integrating CFindFileDlg into your own application

    1. Add these files to your project:
      • FileFindDlg.cpp, FileFindDlg.h
      • FileFinder.cpp, FileFinder.h
    2. Copy the IDD_FIND_FILE dialog from the demo resource file to your project
    3. Copy the 12 animation icons (IDI_ICON1 -> IDI_ICON12) from the demo resource to your project
    4. #include "FindFileDlg.h" in the file where you want to use the dialog.

    Using CFindFileDlg

    // declare a search dialog
    CFindFileDlg dlg;
    
    dlg.m_csRootFolder = "C:\\";      // root folder of search
    dlg.m_csFindFile = "file.ext";  // file to search for
    dlg.m_bRecurse = true;          // search subfolders
    
    dlg.m_bFindSingleFile = false;  // find multiple files
    
    // these next three options aren't strictly necessary here, because
    // we've already specified a root folder. if we left the root folder
    // blank (""), the code will search drives A through Z. 
    //
    // the options below allow you to exclude certain types of drives
    
    dlg.m_bSearchNetworkDrives = false;     // ignore network drives
    dlg.m_bSearchRemovableDrives = false;   // ignore removable drives
    dlg.m_bSearchCDROMDrives = false;       // ignore CD-ROM drives
    
    // do it. 
    int nResponse = dlg.DoModal();
    
    // done
    if (nResponse == IDOK)
    {
        // success!!!
        // dlg.m_csaFoundFiles contains the files that matched our search criteria
    }
    else if (nResponse == IDCANCEL)
    {
        // operation failed or was cancelled
    }
    

    History

    20 Mar 2001 - udpated zip

    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

    Share

    About the Author

    Chris Losinger
    Software Developer
    United States United States
    Chris Losinger is the president of Smaller Animals Software, Inc..

    You may also be interested in...

    Comments and Discussions

     
    QuestionWant to search the root folder and subfolders? Pin
    chris1757-Mar-06 5:53
    memberchris1757-Mar-06 5:53 
    QuestionHow to use this code to find like Files Pin
    chris17521-Feb-06 8:02
    memberchris17521-Feb-06 8:02 
    GeneralBackground thread Pin
    newkie12-Jan-05 23:46
    membernewkie12-Jan-05 23:46 
    QuestionC:\RECYCLER folder? Pin
    Angus Comber28-Feb-04 4:42
    memberAngus Comber28-Feb-04 4:42 
    AnswerRe: C:\RECYCLER folder? Pin
    DgMv20-Dec-05 6:30
    memberDgMv20-Dec-05 6:30 
    QuestionCan it start it a separate thread? Pin
    Christopher Spiteri27-Nov-02 0:59
    memberChristopher Spiteri27-Nov-02 0:59 
    AnswerRe: Can it start it a separate thread? Pin
    Christopher Spiteri27-Nov-02 4:57
    memberChristopher Spiteri27-Nov-02 4:57 
    GeneralMatching file specs aren't found if they are in the root folder Pin
    Matthew House12-Apr-02 4:14
    memberMatthew House12-Apr-02 4:14 
    GeneralToo many backslashes in returned path Pin
    Mike Eriksson16-Mar-01 5:13
    memberMike Eriksson16-Mar-01 5:13 
    GeneralRe: Too many backslashes in returned path Pin
    Chris Losinger16-Mar-01 5:15
    memberChris Losinger16-Mar-01 5:15 
    GeneralRe: Too many backslashes in returned path Pin
    Mike Eriksson16-Mar-01 5:25
    memberMike Eriksson16-Mar-01 5:25 
    GeneralRe: Too many backslashes in returned path Pin
    Chris Losinger16-Mar-01 5:27
    memberChris Losinger16-Mar-01 5:27 
    GeneralFindFile doesn't start at all for me :o) Pin
    Michael Kuelshammer12-Oct-00 6:25
    sussMichael Kuelshammer12-Oct-00 6:25 
    GeneralRe: FindFile doesn't start at all for me :o) Pin
    chris losinger12-Oct-00 6:39
    susschris losinger12-Oct-00 6:39 
    GeneralRe: FindFile doesn't start at all for me :o) Pin
    Michael Kuelshammer15-Oct-00 23:58
    sussMichael Kuelshammer15-Oct-00 23:58 
    GeneralMemory Leaks Pin
    Brigg Thorp10-Jul-00 3:28
    sussBrigg Thorp10-Jul-00 3:28 
    GeneralRe: Memory Leaks Pin
    chris losinger10-Jul-00 3:59
    susschris losinger10-Jul-00 3:59 
    GeneralRe: Memory Leaks - are you sure? Pin
    chris losinger10-Jul-00 4:35
    susschris losinger10-Jul-00 4:35 
    GeneralRe: Memory Leaks - are you sure? Pin
    Brigg Thorp11-Jul-00 7:17
    sussBrigg Thorp11-Jul-00 7:17 
    GeneralRe: Memory Leaks - Fixed Pin
    chris losinger11-Jul-00 10:55
    susschris losinger11-Jul-00 10:55 
    GeneralTo Use the Windows Find Files dialog box Pin
    Brian Hart7-Jul-00 20:27
    sussBrian Hart7-Jul-00 20:27 
    GeneralRe: To Use the Windows Find Files dialog box Pin
    Brian Hart7-Jul-00 20:32
    sussBrian Hart7-Jul-00 20:32 
    GeneralRe: To Use the Windows Find Files dialog box Pin
    Paul Selormey2-Aug-00 10:09
    sussPaul Selormey2-Aug-00 10:09 
    GeneralRe: To Use the Windows Find Files dialog box Pin
    Jason16-Oct-00 4:15
    sussJason16-Oct-00 4:15 
    GeneralRe: To Use the Windows Find Files dialog box Pin
    Chris16-Oct-00 4:17
    sussChris16-Oct-00 4:17 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
    Web02 | 2.8.160730.1 | Last Updated 20 Mar 2001
    Article Copyright 2000 by Chris Losinger
    Everything else Copyright © CodeProject, 1999-2016
    Layout: fixed | fluid