53 lines
1.0 KiB
C++
53 lines
1.0 KiB
C++
#include "fileHelper.h"
|
|
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
std::string Recon::getPath(const std::string &aFullPath)
|
|
{
|
|
size_t pos = aFullPath.find_last_of('/');
|
|
if (pos != std::string::npos)
|
|
{
|
|
return aFullPath.substr(0, pos);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
bool Recon::endsWithMat(const std::string &aStr)
|
|
{
|
|
if (aStr.length() >= 4)
|
|
{
|
|
return (aStr.compare(aStr.length() - 4, 4, ".mat") == 0);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool Recon::isDirectory(const std::string &aPath)
|
|
{
|
|
struct stat info;
|
|
if (stat(aPath.c_str(), &info) != 0)
|
|
{
|
|
return false;
|
|
}
|
|
return (info.st_mode & S_IFDIR) != 0;
|
|
}
|
|
|
|
std::string Recon::fixPathSlash(const std::string& aPath)
|
|
{
|
|
if(aPath.back() == '/')
|
|
{
|
|
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;
|
|
} |