diff --git a/openVulkanoCpp/IO/FsUtils.cpp b/openVulkanoCpp/IO/FsUtils.cpp index 802b038..c2e84b2 100644 --- a/openVulkanoCpp/IO/FsUtils.cpp +++ b/openVulkanoCpp/IO/FsUtils.cpp @@ -10,25 +10,45 @@ namespace fs = std::filesystem; namespace OpenVulkano { - bool FsUtils::DeleteEmptyDirs(const std::filesystem::path& dir, bool recursive) + bool FsUtils::DeleteEmptyDirs(const std::filesystem::path& dir, const bool recursive) { + bool deleted = false; for (auto& p: fs::directory_iterator(dir)) { if (fs::is_directory(p)) { if (recursive) { - if (IsTreeEmpty(p)) + if (DeleteEmptyDirs(p), recursive) { - fs::remove_all(p); + deleted = true; } } - else if (fs::is_empty(p)) + if (fs::is_empty(p)) { fs::remove(p); + deleted = true; } } } + return deleted; + } + + bool FsUtils::DeleteEmptySubTrees(const std::filesystem::path& dir) + { + bool deleted = false; + for (auto& p: fs::directory_iterator(dir)) + { + if (fs::is_directory(p)) + { + if (IsTreeEmpty(p)) + { + fs::remove_all(p); + deleted = true; + } + } + } + return deleted; } bool FsUtils::IsTreeEmpty(const std::filesystem::path& dir) @@ -44,7 +64,7 @@ namespace OpenVulkano } else { - return false; // found a file, so the directory tree is not empty + return false; } } return true; diff --git a/openVulkanoCpp/IO/FsUtils.hpp b/openVulkanoCpp/IO/FsUtils.hpp index 575b33e..7b74b66 100644 --- a/openVulkanoCpp/IO/FsUtils.hpp +++ b/openVulkanoCpp/IO/FsUtils.hpp @@ -10,10 +10,12 @@ namespace OpenVulkano { - class FsUtils + struct FsUtils { static bool DeleteEmptyDirs(const std::filesystem::path& dir, bool recursive = true); + static bool DeleteEmptySubTrees(const std::filesystem::path& dir); + static bool IsTreeEmpty(const std::filesystem::path& dir); }; } \ No newline at end of file