Click here to Skip to main content
15,895,084 members
Articles / Desktop Programming / MFC

FindFile Class for Windows Projects

Rate me:
Please Sign up or sign in to vote.
4.80/5 (27 votes)
12 Jan 20042 min read 175.8K   2.4K   48  
This class is intended to alleviate the task of finding files and folders in a directory with options such as search filters; exclude file filters, exclude directory filters
I decided to write my own code to search for files and directories, make it IDE independent and add some useful features. The result of my efforts is FindFile, the details of which have been given in this article.
//=============================================================================
// Author: Louka Dlagnekov
// File: wildcard.cpp
// Description: This code compares a file name with a filter to determine
//              whether the filter properly matches the file name.
//              Some of this code is downloaded from
//              http://www.1cplusplusstreet.com/ It has been extended to include
//              multiple filters separated by a ';'
//
// Original copyright notice:
//**************************************
//     
// Name: ^NEW^ -- wildcard string compar
//     e (globbing)
// Description:matches a string against 
//     a wildcard string such as "*.*" or "bl?h
//     .*" etc. This is good for file globbing 
//     or to match hostmasks.
// By: Jack Handy
//
// Returns:1 on match, 0 on no match.
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.1CPlusPlusStreet.com/xq/ASP/txtCodeI
//     d.1680/lngWId.3/qx/vb/scripts/ShowCode.h
//     tm//for details.//**************************************
// 
//=============================================================================

#include <string>

using namespace std;

class wildcard
{
private:

    // check string for substring
    static bool find(const char *s1,const char *s2);

    // replacement for strncmp, allows for '?'
    static bool wc_cmp(const char *s1,const char *s2,int len);

    static bool EndCmp(char *src,const char *cmp);

    static bool StartCmp(char *src,const char *cmp);


public:

    // Allows multiple filters separated by ';'
    static bool match (string file, string filter);
    
    // the main wildcard compare function
    static bool wildcmp(string _findstr, string _cmp);
};




 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions