add Path::is_file() and Path::is_dir()
This commit is contained in:
1 parent
1f9a981e6a
commit
2012591b27
3 files changed
+57
No files matched your search
@@ -1,4 +1,7 @@
|
||||
#include "Path.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
std::string Path::dirname(const std::string & s)
|
||||
{
|
||||
@@ -31,3 +34,23 @@ std::string Path::join(const std::string & first, const std::string & second)
|
||||
}
|
||||
return first + "/" + second;
|
||||
}
|
||||
|
||||
bool Path::is_file(const std::string & s)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(s.c_str(), &st) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return S_ISREG(st.st_mode);
|
||||
}
|
||||
|
||||
bool Path::is_dir(const std::string & s)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(s.c_str(), &st) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
@@ -8,6 +8,8 @@ class Path
|
||||
public:
|
||||
static std::string dirname(const std::string & s);
|
||||
static std::string join(const std::string & first, const std::string & second);
|
||||
static bool is_file(const std::string & s);
|
||||
static bool is_dir(const std::string & s);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user