From 3a857f633fc367c2b7ae2a820dd6af72b3a6a823 Mon Sep 17 00:00:00 2001 From: whyydk <254117058+whyydk@users.noreply.github.com> Date: Wed, 1 Apr 2026 11:50:26 +0200 Subject: [PATCH] fileUtil: Add IsEmptyDir function --- src/common/file_util.cpp | 18 ++++++++++++++++++ src/common/file_util.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 52f406226..26bc50c2d 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -155,6 +155,24 @@ static void StripTailDirSlashes(std::string& fname) { fname.resize(i); } +bool IsEmptyDir(const std::string& folder_path) { + if (!IsDirectory(folder_path)) { + return false; + } + + bool has_entries = false; + + ForeachDirectoryEntry(nullptr, folder_path, + [&has_entries]([[maybe_unused]] u64* num_entries_out, + [[maybe_unused]] const std::string& directory, + [[maybe_unused]] const std::string& virtual_name) -> bool { + has_entries = true; + return false; + }); + + return !has_entries; +} + bool Exists(const std::string& filename) { std::string copy(filename); StripTailDirSlashes(copy); diff --git a/src/common/file_util.h b/src/common/file_util.h index 56dbeea93..2fd81265e 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -121,6 +121,9 @@ private: friend class boost::serialization::access; }; +// Check if a folder is empty +[[nodiscard]] bool IsEmptyDir(const std::string& folder_path); + // Returns true if file filename exists [[nodiscard]] bool Exists(const std::string& filename);