Add exists and mkdir to fileHelper

This commit is contained in:
kradchen
2023-08-01 15:59:23 +08:00
parent 835ae8a950
commit e1b732d4cc
2 changed files with 14 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
#include "fileHelper.h"
#include <sys/stat.h>
#include <unistd.h>
std::string Recon::getPath(const std::string &aFullPath)
{
@@ -38,4 +39,15 @@ std::string Recon::fixPathSlash(const std::string& aPath)
return aPath;
}
return aPath + '/';
}
bool Recon::exists(const std::string &aPath)
{
return access(aPath.c_str(), F_OK) == 0;
}
bool Recon::mkdir(const std::string &aPath)
{
if(isDirectory(aPath)) return true;
return ::mkdir(aPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0;
}

View File

@@ -12,6 +12,8 @@ namespace Recon
std::string getPath(const std::string &aFullPath);
bool endsWithMat(const std::string &aStr);
bool isDirectory(const std::string &aPath);
bool exists(const std::string &aPath);
bool mkdir(const std::string &aPath);
std::string fixPathSlash(const std::string& aPath);
}