Example #1
0
/**
* @brief findMatrices
* @param root path to the directory where to search for files with extension
* @param extension matrix files extension without "." just mtx
* @param matrix_files vector of found files with given extension
* @return true if any files were found
*/
bool findMatrices( const std::string& root,
    const std::string& extension,
    std::vector<fs::path>& matrix_files )
{
    fs::path dir( root );

        recursive_directory_range recursive_directory_it(dir);

        const boost::regex filter( ".*\\.\\" + extension );
        bool found = false;

        if( fs::exists( dir ) && fs::is_directory( dir ) )
        {
            for (auto it : recursive_directory_range(dir))
            {
                //std::cout << "Checking:" << it << std::endl;
                if( fs::is_regular_file( it.status( ) ) )
                {
                    std::string fname = it.path( ).filename( ).string( );

                    std::string fname_suffix = fname.substr(fname.size() - 6);

                    if( boost::regex_match( fname, filter ) )
                    {
                        std::cout << "\tAdding:" << it.path( ) << std::endl;
                        matrix_files.push_back( it.path( ) );
                        found = true;
                    }
                }
            }
        }
        else
        {
            std::cerr << dir << " does not name a directory or directory does not exists!" << std::endl;
            return false;
        }

        return found;
}
Example #2
0
void print_filePath(const std::string & dir_path) {
  for (auto it : recursive_directory_range(dir_path)) {
    std::cout << it << std::endl;
  }
}