Recursive file search using C++ MFC?

后端 未结 5 1176
失恋的感觉
失恋的感觉 2020-12-06 14:45

What is the cleanest way to recursively search for files using C++ and MFC?

EDIT: Do any of these solutions offer the ability to use multiple filters through one pas

5条回答
  •  心在旅途
    2020-12-06 15:17

    Use Boost's Filesystem implementation!

    The recursive example is even on the filesystem homepage:

    bool find_file( const path & dir_path,         // in this directory,
                    const std::string & file_name, // search for this name,
                    path & path_found )            // placing path here if found
    {
      if ( !exists( dir_path ) ) return false;
      directory_iterator end_itr; // default construction yields past-the-end
      for ( directory_iterator itr( dir_path );
            itr != end_itr;
            ++itr )
      {
        if ( is_directory(itr->status()) )
        {
          if ( find_file( itr->path(), file_name, path_found ) ) return true;
        }
        else if ( itr->leaf() == file_name ) // see below
        {
          path_found = itr->path();
          return true;
        }
      }
      return false;
    }
    

提交回复
热议问题