Skip to content
Snippets Groups Projects
Commit c9c06d39 authored by ilor's avatar ilor
Browse files

add PathSearcher::list_files to find a list of files in the search path matching an extension

parent 5f30bdd8
No related merge requests found
......@@ -100,6 +100,24 @@ bool PathSearcherBase::open_stream(const std::string& filename,
return false;
}
std::vector<std::string> PathSearcherBase::list_files(const std::string& suffix) const
{
using boost::filesystem::directory_iterator;
std::vector<std::string> out;
foreach (const std::string& s, get_search_path()) {
boost::filesystem::path p(s);
if (boost::filesystem::is_directory(s)) {
for (directory_iterator i(p); i != directory_iterator(); ++i) {
boost::filesystem::path in = i->path();
if (in.extension() == suffix) {
out.push_back(in.stem());
}
}
}
}
return out;
}
ConfigPathSetter::ConfigPathSetter(PathSearcherBase& ps,
const std::string &new_path)
......
......@@ -85,6 +85,11 @@ public:
bool open_stream(const std::string& filename, std::ifstream& ifs,
const std::string& info = "");
/**
* Look for files matching a condition.
*/
std::vector<std::string> list_files(const std::string& suffix) const;
private:
/// The search paths
std::vector<std::string> paths_;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment