Commit b10a5c3f authored by Sebastian Wolf's avatar Sebastian Wolf

Add get_directories to fileUtilities

parent ac2b88d1
......@@ -35,8 +35,11 @@ namespace xerus { namespace misc {
///@brief Creates all directories in the @a _path of the file, if needed.
void create_directories_for_file(const std::string& _path);
///@brief Returns a set containing all regular files at the given @a _path.
///@brief Returns a set containing all regular files present at the given @a _path.
std::set<std::string> get_files(const std::string& _path);
///@brief Returns a set containing all directories present at the given @a _path.
std::set<std::string> get_directories(const std::string& _path);
///@brief Checks whether a file at the given @a _path exists.
bool file_exists(const std::string& _path);
......
......@@ -47,6 +47,7 @@ namespace xerus { namespace misc {
}
}
std::set<std::string> get_files(const std::string& _path) {
REQUIRE(boost::filesystem::exists(_path) && boost::filesystem::is_directory(_path), "Invalid path " << _path << " (not an existing directory).");
std::set<std::string> files;
......@@ -60,6 +61,21 @@ namespace xerus { namespace misc {
return files;
}
std::set<std::string> get_directories(const std::string& _path) {
REQUIRE(boost::filesystem::exists(_path) && boost::filesystem::is_directory(_path), "Invalid path " << _path << " (not an existing directory).");
std::set<std::string> files;
for (boost::filesystem::directory_iterator itr(_path), end; itr != end; ++itr) {
if(!boost::filesystem::is_directory(itr->path())) { continue;}
const auto file = itr->path().filename().string();
files.emplace(file);
}
return files;
}
bool file_exists(const std::string& _path) {
return boost::filesystem::exists(_path);
}
......
Markdown is supported
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