Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
graphite/engine/platform/emscripten/filesystem.cpp

36 lines
772 B
C++
Raw Permalink Normal View History

2024-01-03 16:05:02 -05:00
#include "filesystem.hpp"
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
bool Filesystem::DirectoryExists(const std::string& path)
{
DIR* dir = opendir(path.c_str());
return dir != nullptr;
}
bool Filesystem::FileExists(const std::string& path)
{
return access(path.c_str(), F_OK) != -1;
}
std::vector<std::string> Filesystem::DirectoryContents(const std::string& directory)
{
std::vector<std::string> tmp;
DIR* dir;
dirent* ent;
if ((dir = opendir(directory.c_str())) != nullptr) {
while ((ent = readdir (dir)) != nullptr) {
if(ent->d_name != "." && ent->d_name != "..")
{
tmp.push_back(ent->d_name);
}
}
closedir (dir);
}
return tmp;
}