Added Listing directories and filtering filenames by regex
This commit is contained in:
parent
7a1eca7265
commit
6e86eacf5a
|
@ -13,6 +13,7 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -123,6 +124,9 @@ struct FileInfo {
|
||||||
};
|
};
|
||||||
bool GetInfo(const std::filesystem::path& path, FileInfo* out_info);
|
bool GetInfo(const std::filesystem::path& path, FileInfo* out_info);
|
||||||
std::vector<FileInfo> ListFiles(const std::filesystem::path& path);
|
std::vector<FileInfo> ListFiles(const std::filesystem::path& path);
|
||||||
|
std::vector<FileInfo> ListDirectories(const std::filesystem::path& path);
|
||||||
|
std::vector<FileInfo> FilterByName(const std::vector<FileInfo>& files,
|
||||||
|
const std::regex pattern);
|
||||||
|
|
||||||
#if XE_PLATFORM_ANDROID
|
#if XE_PLATFORM_ANDROID
|
||||||
void AndroidInitialize();
|
void AndroidInitialize();
|
||||||
|
|
|
@ -261,5 +261,29 @@ std::vector<FileInfo> ListFiles(const std::filesystem::path& path) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<FileInfo> ListDirectories(const std::filesystem::path& path) {
|
||||||
|
std::vector<FileInfo> files = ListFiles(path);
|
||||||
|
std::vector<FileInfo> directories = {};
|
||||||
|
|
||||||
|
std::copy_if(
|
||||||
|
files.cbegin(), files.cend(), std::back_inserter(directories),
|
||||||
|
[](FileInfo file) { return file.type == FileInfo::Type::kDirectory; });
|
||||||
|
|
||||||
|
return directories;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<FileInfo> FilterByName(const std::vector<FileInfo>& files,
|
||||||
|
const std::regex pattern) {
|
||||||
|
std::vector<FileInfo> filtered_entries = {};
|
||||||
|
|
||||||
|
std::copy_if(files.cbegin(), files.cend(),
|
||||||
|
std::back_inserter(filtered_entries), [pattern](FileInfo file) {
|
||||||
|
return std::regex_match(file.name.filename().string(),
|
||||||
|
pattern);
|
||||||
|
});
|
||||||
|
|
||||||
|
return filtered_entries;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace filesystem
|
} // namespace filesystem
|
||||||
} // namespace xe
|
} // namespace xe
|
||||||
|
|
Loading…
Reference in New Issue