src/sgp/FileMan.cc
/**
 * Find all files with the given extension in the given directory.
 * @param dirPath Path to the directory
 * @param extension Extension with dot (e.g. ".txt")
 * @param caseIncensitive When True, do case-insensitive search even of case-sensitive file-systems. * * @return List of paths (dir + filename). */
Find all files with the given extension in the given directory.
@param dirPath Path to the directory
@param extension Extension with dot
@param caseIncensitive When True, do case-insensitive search even of case-sensitive file-systems. * * @return List of paths (dir + filename).
Find all files with the given extension in the given directory . @param dirPath Path to the directory @param extension Extension with dot @param caseIncensitive When True do case - insensitive search even of case - sensitive file - systems . * * @return List of paths ( dir + filename ) .
std::vector<std::string>
FindFilesInDir(const std::string &dirPath,
		const std::string &ext,
		bool caseIncensitive,
		bool returnOnlyNames,
		bool sortResults)
{
	std::string ext_copy = ext;
	if(caseIncensitive)
	{
		std::transform(ext_copy.begin(), ext_copy.end(), ext_copy.begin(), ::tolower);
	}
	std::vector<std::string> paths;
	boost::filesystem::path path(dirPath);
	boost::filesystem::directory_iterator end;
	for(boost::filesystem::directory_iterator it(path); it != end; it++)
	{
		if(boost::filesystem::is_regular_file(it->status()))
		{
			std::string file_ext = it->path().extension().string();
			if(caseIncensitive)
			{
				std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), ::tolower);
			}
			if(file_ext.compare(ext_copy) == 0)
			{
				if(returnOnlyNames)
				{
					paths.push_back(it->path().filename().string());
				}
				else
				{
					paths.push_back(it->path().string());
				}
			}
		}
	}
	if(sortResults)
	{
		std::sort(paths.begin(), paths.end());
	}
	return paths;
}
std :: vector < std :: string > FindFilesInDir ( const std :: string & dirPath , const std :: string & ext , bool caseIncensitive , bool returnOnlyNames , bool sortResults ) { std :: string ext_copy = ext ; if ( caseIncensitive ) { std :: transform ( ext_copy . begin ( ) , ext_copy . end ( ) , ext_copy . begin ( ) , :: tolower ) ; } std :: vector < std :: string > paths ; boost :: filesystem :: path path ( dirPath ) ; boost :: filesystem :: directory_iterator end ; for ( boost :: filesystem :: directory_iterator it ( path ) ; it != end ; it ++ ) { if ( boost :: filesystem :: is_regular_file ( it -> status ( ) ) ) { std :: string file_ext = it -> path ( ) . extension ( ) . string ( ) ; if ( caseIncensitive ) { std :: transform ( file_ext . begin ( ) , file_ext . end ( ) , file_ext . begin ( ) , :: tolower ) ; } if ( file_ext . compare ( ext_copy ) == 0 ) { if ( returnOnlyNames ) { paths . push_back ( it -> path ( ) . filename ( ) . string ( ) ) ; } else { paths . push_back ( it -> path ( ) . string ( ) ) ; } } } } if ( sortResults ) { std :: sort ( paths . begin ( ) , paths . end ( ) ) ; } return paths ; }
Find all files with the given extension in the given directory.
Find all files with the given extension in the given directory .