/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "FsUtils.hpp" namespace fs = std::filesystem; namespace OpenVulkano { bool FsUtils::DeleteEmptyDirs(const std::filesystem::path& dir, bool recursive) { for (auto& p: fs::directory_iterator(dir)) { if (fs::is_directory(p)) { if (recursive) { if (IsTreeEmpty(p)) { fs::remove_all(p); } } else if (fs::is_empty(p)) { fs::remove(p); } } } } bool FsUtils::IsTreeEmpty(const std::filesystem::path& dir) { for (auto& p: fs::directory_iterator(dir)) { if (fs::is_directory(p)) { if (!IsTreeEmpty(p)) { return false; } } else { return false; // found a file, so the directory tree is not empty } } return true; } }