Browse Source

Use POSIX implementation of filesystemListDirectory

tags/v0.6.0
Andrew Belt 7 years ago
parent
commit
3177ec30fc
1 changed files with 2 additions and 20 deletions
  1. +2
    -20
      src/main.cpp

+ 2
- 20
src/main.cpp View File

@@ -10,11 +10,7 @@


#include <unistd.h> #include <unistd.h>


#if defined(ARCH_WIN)
#include <windows.h>
#else
#include <glob.h>
#endif
#include <dirent.h>




using namespace rack; using namespace rack;
@@ -22,31 +18,17 @@ using namespace rack;


std::vector<std::string> filesystemListDirectory(std::string path) { std::vector<std::string> filesystemListDirectory(std::string path) {
std::vector<std::string> filenames; std::vector<std::string> filenames;
#if defined(ARCH_WIN)
WIN32_FIND_DATA findData;
HANDLE findHandle = FindFirstFile((path + "/*").c_str(), &findData);
if (findHandle != INVALID_HANDLE_VALUE) {
do {
std::string filename = findData.cFileName;
if (filename == "." || filename == "..")
continue;
filenames.push_back(path + "/" + filename);
} while (FindNextFile(findHandle, &findData));
FindClose(findHandle);
}
#else
DIR *dir = opendir(path.c_str()); DIR *dir = opendir(path.c_str());
if (dir) { if (dir) {
struct dirent *d; struct dirent *d;
while ((d = readdir(dir))) { while ((d = readdir(dir))) {
std::string filename = d->f_name;
std::string filename = d->d_name;
if (filename == "." || filename == "..") if (filename == "." || filename == "..")
continue; continue;
filenames.push_back(path + "/" + filename); filenames.push_back(path + "/" + filename);
} }
closedir(dir); closedir(dir);
} }
#endif
return filenames; return filenames;
} }




Loading…
Cancel
Save