diff --git a/libpwrutils/pathsearch.cpp b/libpwrutils/pathsearch.cpp index e130c0272c202ffab4bf1281e3d611db0135c5a5..c89b7a4bf1af495ca866ffbc62bb7a3656d24ff3 100644 --- a/libpwrutils/pathsearch.cpp +++ b/libpwrutils/pathsearch.cpp @@ -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) diff --git a/libpwrutils/pathsearch.h b/libpwrutils/pathsearch.h index 6a1696ac7ab9dcaa928861ceb4ef24edcee42cff..956f68deab9b0282b4b33d5a72c408495a9626a0 100644 --- a/libpwrutils/pathsearch.h +++ b/libpwrutils/pathsearch.h @@ -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_;