fileUtil: Add IsEmptyDir function

This commit is contained in:
whyydk 2026-04-01 11:50:26 +02:00
parent 4e6ff317dd
commit 3a857f633f
2 changed files with 21 additions and 0 deletions

View File

@ -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);

View File

@ -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);