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