36 lines
No EOL
772 B
C++
36 lines
No EOL
772 B
C++
#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;
|
|
} |