From e36c4837ccb252aa3ca040ff60e9fb2f9cc6114f Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Fri, 9 Aug 2024 14:52:48 +0200 Subject: [PATCH] Add recursive dir size getter --- openVulkanoCpp/IO/FsUtils.cpp | 21 ++++++++++++++++++++- openVulkanoCpp/IO/FsUtils.hpp | 5 ++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/openVulkanoCpp/IO/FsUtils.cpp b/openVulkanoCpp/IO/FsUtils.cpp index c2e84b2..3a3595a 100644 --- a/openVulkanoCpp/IO/FsUtils.cpp +++ b/openVulkanoCpp/IO/FsUtils.cpp @@ -69,4 +69,23 @@ namespace OpenVulkano } return true; } -} \ No newline at end of file + + ByteSize FsUtils::GetDirSize(const std::filesystem::path& dir) + { + ByteSize size = 0; + + for (auto& p: fs::directory_iterator(dir)) + { + if (fs::is_directory(p)) + { + size += GetDirSize(p); + } + else + { + size += p.file_size(); + } + } + + return size; + } +} diff --git a/openVulkanoCpp/IO/FsUtils.hpp b/openVulkanoCpp/IO/FsUtils.hpp index 7b74b66..4dc397c 100644 --- a/openVulkanoCpp/IO/FsUtils.hpp +++ b/openVulkanoCpp/IO/FsUtils.hpp @@ -6,6 +6,7 @@ #pragma once +#include "Math/ByteSize.hpp" #include namespace OpenVulkano @@ -17,5 +18,7 @@ namespace OpenVulkano static bool DeleteEmptySubTrees(const std::filesystem::path& dir); static bool IsTreeEmpty(const std::filesystem::path& dir); + + static ByteSize GetDirSize(const std::filesystem::path& dir); }; -} \ No newline at end of file +}