Use std::filesystem instead of dirent.h
This commit is contained in:
parent
3c94c57558
commit
07ccce90d3
|
@ -1,6 +1,5 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <filesystem>
|
||||
|
||||
#include <paths.hpp>
|
||||
|
||||
|
@ -8,24 +7,14 @@
|
|||
|
||||
// get models from a given directory and add them to a given vector
|
||||
void getModelsFromDir(std::string path, std::vector<std::string>* vector) {
|
||||
DIR* dir;
|
||||
struct dirent* ent;
|
||||
// return if directory doesnt exist
|
||||
if (!std::filesystem::exists(path)) return;
|
||||
|
||||
if ((dir = opendir(path.c_str())) != NULL) {
|
||||
while ((ent = readdir(dir)) != NULL) {
|
||||
std::string filename = ent->d_name;
|
||||
size_t fmaPos = filename.find(".fma"); // position of ".fma" in filename
|
||||
|
||||
if (fmaPos == std::string::npos) {
|
||||
// filename does not have ".fma" in it
|
||||
continue;
|
||||
// iterate through all items in this directory
|
||||
for (auto& p: std::filesystem::directory_iterator(path)) {
|
||||
if (p.path().extension() == ".fma") {
|
||||
vector->push_back(p.path().stem().string());
|
||||
}
|
||||
|
||||
filename.erase(fmaPos);
|
||||
|
||||
vector->push_back(filename);
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue