41 #include "BESFSFile.h" 43 BESFSFile::BESFSFile(
const string &fullPath) :
44 _dirName(
""), _fileName(
""), _baseName(
""), _extension(
"")
49 BESFSFile::BESFSFile(
const string &dirName,
const string &fileName) :
50 _dirName(dirName), _fileName(fileName), _baseName(
""), _extension(
"")
55 BESFSFile::BESFSFile(
const BESFSFile ©From) :
56 _dirName(copyFrom._dirName), _fileName(copyFrom._fileName), _baseName(copyFrom._baseName), _extension(
61 BESFSFile::~BESFSFile()
65 string BESFSFile::getDirName()
70 string BESFSFile::getFileName()
75 string BESFSFile::getBaseName()
80 string BESFSFile::getExtension()
85 string BESFSFile::getFullPath()
87 return _dirName +
"/" + _fileName;
90 void BESFSFile::breakApart(
const string &fullPath)
92 string::size_type pos = fullPath.rfind(
"/");
93 if (pos != string::npos) {
94 _dirName = fullPath.substr(0, pos);
95 _fileName = fullPath.substr(pos + 1, fullPath.length() - pos);
105 void BESFSFile::breakExtension()
107 string::size_type pos = _fileName.rfind(
".");
108 if (pos != string::npos) {
109 _baseName = _fileName.substr(0, pos);
110 _extension = _fileName.substr(pos + 1, _fileName.length() - pos);
113 _baseName = _fileName;
117 bool BESFSFile::exists(
string &reason)
120 if (!access(getFullPath().c_str(), F_OK)) {
124 char *err = strerror(errno);
129 reason +=
"Unknown error";
135 bool BESFSFile::isReadable(
string &reason)
138 if (!access(getFullPath().c_str(), R_OK)) {
142 char *err = strerror(errno);
147 reason +=
"Unknown error";
153 bool BESFSFile::isWritable(
string &reason)
156 if (!access(getFullPath().c_str(), W_OK)) {
160 char *err = strerror(errno);
165 reason +=
"Unknown error";
171 bool BESFSFile::isExecutable(
string &reason)
174 if (!access(getFullPath().c_str(), X_OK)) {
178 char *err = strerror(errno);
183 reason +=
"Unknown error";
189 bool BESFSFile::hasDotDot()
192 string fp = getFullPath();
193 if (fp.find(
"..") != string::npos) {