Click here to Skip to main content
Licence 
First Posted 5 Jul 2000
Views 134,469
Bookmarked 29 times

Easy to use file finding dialog

By | 19 Mar 2001 | Article
An easy to use multi-threaded dialog class that will search disks for files. Similar to Explorer's "Find Files of Folders" tool.
  • Download demo project - 21 Kb
  • Sample Image - FindFileSearching.gif

    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

    About the Author

    Chris Losinger

    Software Developer

    United States United States

    Member

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

    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
    QuestionWant to search the root folder and subfolders? Pinmemberchris1755:53 7 Mar '06  
    QuestionHow to use this code to find like Files Pinmemberchris1758:02 21 Feb '06  
    GeneralBackground thread Pinmembernewkie23:46 12 Jan '05  
    QuestionC:\RECYCLER folder? PinmemberAngus Comber4:42 28 Feb '04  
    AnswerRe: C:\RECYCLER folder? PinmemberDgMv6:30 20 Dec '05  
    QuestionCan it start it a separate thread? PinmemberChristopher Spiteri0:59 27 Nov '02  
    AnswerRe: Can it start it a separate thread? PinmemberChristopher Spiteri4:57 27 Nov '02  
    GeneralMatching file specs aren't found if they are in the root folder PinmemberMatthew House4:14 12 Apr '02  
    GeneralToo many backslashes in returned path PinmemberMike Eriksson5:13 16 Mar '01  
    GeneralRe: Too many backslashes in returned path PinmemberChris Losinger5:15 16 Mar '01  
    GeneralRe: Too many backslashes in returned path PinmemberMike Eriksson5:25 16 Mar '01  
    GeneralRe: Too many backslashes in returned path PinmemberChris Losinger5:27 16 Mar '01  
    Smile | :) ok. you got me.
     
    -c
     
    ------------------------------
    Smaller Animals Software, Inc.
    http://www.smalleranimals.com
    GeneralFindFile doesn't start at all for me :o) PinsussMichael Kuelshammer6:25 12 Oct '00  
    GeneralRe: FindFile doesn't start at all for me :o) Pinsusschris losinger6:39 12 Oct '00  
    GeneralRe: FindFile doesn't start at all for me :o) PinsussMichael Kuelshammer23:58 15 Oct '00  
    GeneralMemory Leaks PinsussBrigg Thorp3:28 10 Jul '00  
    GeneralRe: Memory Leaks Pinsusschris losinger3:59 10 Jul '00  
    GeneralRe: Memory Leaks - are you sure? Pinsusschris losinger4:35 10 Jul '00  
    GeneralRe: Memory Leaks - are you sure? PinsussBrigg Thorp7:17 11 Jul '00  
    GeneralRe: Memory Leaks - Fixed Pinsusschris losinger10:55 11 Jul '00  
    GeneralTo Use the Windows Find Files dialog box PinsussBrian Hart20:27 7 Jul '00  
    GeneralRe: To Use the Windows Find Files dialog box PinsussBrian Hart20:32 7 Jul '00  
    GeneralRe: To Use the Windows Find Files dialog box PinsussPaul Selormey10:09 2 Aug '00  
    GeneralRe: To Use the Windows Find Files dialog box PinsussJason4:15 16 Oct '00  
    GeneralRe: To Use the Windows Find Files dialog box PinsussChris4:17 16 Oct '00  

    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.120529.1 | Last Updated 20 Mar 2001
    Article Copyright 2000 by Chris Losinger
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid