Skip to content

Commit 2ff4ff6

Browse files
committed
[Base] Added Listing directories and filtering filenames by regex
1 parent c5e6352 commit 2ff4ff6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/xenia/base/filesystem.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,30 @@ bool CreateParentFolder(const std::filesystem::path& path) {
2424
return true;
2525
}
2626

27+
std::vector<FileInfo> ListDirectories(const std::filesystem::path& path) {
28+
const std::vector<FileInfo> files = ListFiles(path);
29+
std::vector<FileInfo> directories = {};
30+
31+
std::copy_if(files.cbegin(), files.cend(), std::back_inserter(directories),
32+
[](const FileInfo& file) {
33+
return file.type == FileInfo::Type::kDirectory;
34+
});
35+
36+
return directories;
37+
}
38+
39+
std::vector<FileInfo> FilterByName(const std::vector<FileInfo>& files,
40+
const std::regex pattern) {
41+
std::vector<FileInfo> filtered_entries = {};
42+
43+
std::copy_if(
44+
files.cbegin(), files.cend(), std::back_inserter(filtered_entries),
45+
[pattern](const FileInfo& file) {
46+
return std::regex_match(file.name.filename().string(), pattern);
47+
});
48+
49+
return filtered_entries;
50+
}
51+
2752
} // namespace filesystem
2853
} // namespace xe

src/xenia/base/filesystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <filesystem>
1414
#include <iterator>
1515
#include <memory>
16+
#include <regex>
1617
#include <string>
1718
#include <string_view>
1819
#include <vector>
@@ -123,6 +124,9 @@ struct FileInfo {
123124
};
124125
bool GetInfo(const std::filesystem::path& path, FileInfo* out_info);
125126
std::vector<FileInfo> ListFiles(const std::filesystem::path& path);
127+
std::vector<FileInfo> ListDirectories(const std::filesystem::path& path);
128+
std::vector<FileInfo> FilterByName(const std::vector<FileInfo>& files,
129+
const std::regex pattern);
126130

127131
#if XE_PLATFORM_ANDROID
128132
void AndroidInitialize();

0 commit comments

Comments
 (0)