Add FilesWithExtension function
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "FsUtils.hpp"
|
#include "FsUtils.hpp"
|
||||||
#include "Base/Logger.hpp"
|
#include "Base/Logger.hpp"
|
||||||
|
#include "Base/Utils.hpp"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
@@ -192,4 +193,37 @@ namespace OpenVulkano
|
|||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::filesystem::path> FsUtils::FilesWithExtension(const std::filesystem::path& dir, std::string ext)
|
||||||
|
{
|
||||||
|
std::vector<std::filesystem::path> files;
|
||||||
|
|
||||||
|
if (!fs::exists(dir) || !fs::is_directory(dir))
|
||||||
|
{
|
||||||
|
Logger::FILESYS->warn("Directory does not exist or is not a directory: {}", dir.string());
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ext.empty() && ext[0] != '.') ext = "." + ext;
|
||||||
|
Utils::ToLower(ext);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (const auto& entry : fs::directory_iterator(dir))
|
||||||
|
{
|
||||||
|
std::string fExt = entry.path().extension().string();
|
||||||
|
Utils::ToLower(fExt);
|
||||||
|
if (fs::is_regular_file(entry) && fExt == ext)
|
||||||
|
{
|
||||||
|
files.push_back(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const fs::filesystem_error& e)
|
||||||
|
{
|
||||||
|
Logger::FILESYS->error("Filesystem error when searching for files: {}", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,5 +40,7 @@ namespace OpenVulkano
|
|||||||
static FsCount GetDirFileAndDirCount(const std::filesystem::path& dir);
|
static FsCount GetDirFileAndDirCount(const std::filesystem::path& dir);
|
||||||
|
|
||||||
static std::string ToValidFileName(std::string filename);
|
static std::string ToValidFileName(std::string filename);
|
||||||
|
|
||||||
|
static std::vector<std::filesystem::path> FilesWithExtension(const std::filesystem::path& dir, std::string ext);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user