better code for getDirectoryEntries

This commit is contained in:
wheremyfoodat 2023-11-08 12:04:26 +02:00 committed by georgemoralis
parent 1ced777f20
commit e35efb55a2
1 changed files with 6 additions and 6 deletions

View File

@ -1,4 +1,5 @@
#include "common/fs_file.h" #include "common/fs_file.h"
#include <filesystem> #include <filesystem>
namespace Common::FS { namespace Common::FS {
@ -58,7 +59,7 @@ u64 File::tell() const {
return -1; return -1;
} }
std::vector<DirEntry> File::getDirectoryEntries(const std::string& path) { std::vector<DirEntry> File::getDirectoryEntries(const std::string& path) {
std::string curpath = path; std::string curpath = path;
if (!curpath.ends_with("/")) { if (!curpath.ends_with("/")) {
curpath = std::string(curpath + "/"); curpath = std::string(curpath + "/");
@ -66,17 +67,16 @@ std::vector<DirEntry> File::getDirectoryEntries(const std::string& path) {
std::vector<DirEntry> files; std::vector<DirEntry> files;
for (const auto& entry : std::filesystem::directory_iterator(curpath)) { for (const auto& entry : std::filesystem::directory_iterator(curpath)) {
if (std::filesystem::is_regular_file( entry.path().string())) { DirEntry e = {};
DirEntry e = {}; if (std::filesystem::is_regular_file(entry.path().string())) {
e.name = entry.path().filename().string(); e.name = entry.path().filename().string();
e.isFile = true; e.isFile = true;
files.push_back(e);
} else { } else {
DirEntry e = {}; DirEntry e = {};
e.name = entry.path().filename().string() + "/"; //hmmm not sure if it has to be like this... e.name = entry.path().filename().string() + "/"; // hmmm not sure if it has to be like this...
e.isFile = false; e.isFile = false;
files.push_back(e);
} }
files.push_back(e);
} }
return files; return files;