41 #include "BESFSFile.h" 43 BESFSFile::BESFSFile(
const string &fullPath)
49 breakApart(fullPath) ;
52 BESFSFile::BESFSFile(
const string &dirName,
const string &fileName)
61 BESFSFile::BESFSFile(
const BESFSFile ©From)
62 : _dirName(copyFrom._dirName),
63 _fileName(copyFrom._fileName),
64 _baseName(copyFrom._baseName),
65 _extension(copyFrom._extension)
68 BESFSFile::~BESFSFile()
72 BESFSFile::getDirName()
78 BESFSFile::getFileName()
84 BESFSFile::getBaseName()
90 BESFSFile::getExtension()
96 BESFSFile::getFullPath()
98 return _dirName +
"/" + _fileName ;
102 BESFSFile::breakApart(
const string &fullPath)
104 string::size_type pos = fullPath.rfind(
"/") ;
105 if (pos != string::npos) {
106 _dirName = fullPath.substr(0, pos) ;
107 _fileName = fullPath.substr(pos + 1, fullPath.length() - pos) ;
111 _fileName = fullPath ;
118 BESFSFile::breakExtension()
120 string::size_type pos = _fileName.rfind(
".") ;
121 if (pos != string::npos) {
122 _baseName = _fileName.substr(0, pos) ;
123 _extension = _fileName.substr(pos + 1, _fileName.length() - pos) ;
126 _baseName = _fileName ;
131 BESFSFile::exists(
string &reason )
134 if( !access( getFullPath().c_str(), F_OK ) )
140 char *err = strerror( errno ) ;
147 reason +=
"Unknown error" ;
154 BESFSFile::isReadable(
string &reason )
157 if( !access( getFullPath().c_str(), R_OK ) )
163 char *err = strerror( errno ) ;
170 reason +=
"Unknown error" ;
177 BESFSFile::isWritable(
string &reason )
180 if( !access( getFullPath().c_str(), W_OK ) )
186 char *err = strerror( errno ) ;
193 reason +=
"Unknown error" ;
200 BESFSFile::isExecutable(
string &reason )
203 if( !access( getFullPath().c_str(), X_OK ) )
209 char *err = strerror( errno ) ;
216 reason +=
"Unknown error" ;
223 BESFSFile::hasDotDot()
226 string fp = getFullPath() ;
227 if( fp.find(
".." ) != string::npos )