add Path::dir_entries()
This commit is contained in:
1 parent
e3cb7b15b4
commit
c001fca012
3 files changed
+29
No files matched your search
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "jes/Ref.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace jes
|
||||
{
|
||||
@@ -15,6 +16,7 @@ namespace jes
|
||||
Path join(const Path & other);
|
||||
const std::string & to_s() { return m_path; }
|
||||
bool exists();
|
||||
std::vector<std::string> dir_entries();
|
||||
protected:
|
||||
void clean();
|
||||
std::string m_path;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
namespace jes
|
||||
{
|
||||
@@ -55,6 +56,24 @@ namespace jes
|
||||
return stat(m_path.c_str(), &st) == 0;
|
||||
}
|
||||
|
||||
std::vector<std::string> Path::dir_entries()
|
||||
{
|
||||
std::vector<std::string> rv;
|
||||
DIR * dir = opendir(m_path.c_str());
|
||||
if (dir != NULL)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
struct dirent * de = readdir(dir);
|
||||
if (de == NULL)
|
||||
break;
|
||||
rv.push_back(std::string(de->d_name));
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
void Path::clean()
|
||||
{
|
||||
for (char & c : m_path)
|
||||
|
||||
Reference in new issue
Block a user