Add more functions
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "FsUtils.hpp"
|
||||
#include "Base/Logger.hpp"
|
||||
#include <unordered_map>
|
||||
#include <regex>
|
||||
|
||||
@@ -12,6 +13,34 @@ namespace fs = std::filesystem;
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
bool FsUtils::DeleteEmptyFilesAndDirs(const std::filesystem::path& dir, const bool recursive)
|
||||
{
|
||||
bool deleted = false;
|
||||
for (auto& p: fs::directory_iterator(dir))
|
||||
{
|
||||
if (fs::is_directory(p))
|
||||
{
|
||||
if (recursive)
|
||||
{
|
||||
deleted |= (DeleteEmptyDirs(p), recursive);
|
||||
}
|
||||
if (fs::is_empty(p))
|
||||
{
|
||||
fs::remove(p);
|
||||
Logger::FILESYS->info("Deleted empty directory: {}", p.path().string());
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
else if (fs::is_empty(p))
|
||||
{
|
||||
fs::remove(p);
|
||||
Logger::FILESYS->info("Deleted empty file: {}", p.path().string());
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
bool FsUtils::DeleteEmptyDirs(const std::filesystem::path& dir, const bool recursive)
|
||||
{
|
||||
bool deleted = false;
|
||||
@@ -21,14 +50,12 @@ namespace OpenVulkano
|
||||
{
|
||||
if (recursive)
|
||||
{
|
||||
if (DeleteEmptyDirs(p), recursive)
|
||||
{
|
||||
deleted = true;
|
||||
}
|
||||
deleted |= (DeleteEmptyDirs(p), recursive);
|
||||
}
|
||||
if (fs::is_empty(p))
|
||||
{
|
||||
fs::remove(p);
|
||||
Logger::FILESYS->info("Deleted empty directory: {}", p.path().string());
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
@@ -90,6 +117,24 @@ namespace OpenVulkano
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
FsCount FsUtils::GetDirFileAndDirCount(const std::filesystem::path& dir)
|
||||
{
|
||||
FsCount count;
|
||||
for (auto& p: fs::directory_iterator(dir))
|
||||
{
|
||||
if (fs::is_directory(p))
|
||||
{
|
||||
count += GetDirFileAndDirCount(p);
|
||||
count.dirCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
count.fileCount++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
std::string FsUtils::ToValidFileName(std::string str)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user