mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-04-04 20:27:44 -06:00
fileUtil: Add IsEmptyDir function
This commit is contained in:
parent
4e6ff317dd
commit
3a857f633f
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user