37 unlink(fname.c_str());
38 std::string savename_base(fname+
"."+ext);
39 std::string savename(savename_base);
42 std::ostringstream Ostr;
43 Ostr << savename_base << n++;
44 savename.assign(Ostr.str());
46 rename(fname.c_str(),savename.c_str());
53 if(lstat(fname.c_str(),&fstat))
62 if(stat(fname.c_str(),&fstat))
64 if(S_ISDIR(fstat.st_mode))
73 if(lstat(fname.c_str(),&fstat))
75 if(S_ISLNK(fstat.st_mode))
83 return(mkdir(fname.c_str(),S_IRGRP | S_IXGRP | S_IRWXU));
91 size_t s = readlink(path.c_str(),buf,1024);
96 std::string::size_type
x = retVal.find_last_of(
"/");
97 if(x != std::string::npos)
107 size_t s = readlink(path.c_str(),buf,1024);
112 std::string::size_type
x = retVal.find_last_of(
"/");
113 if(x != std::string::npos)
124 std::cerr <<
"Directory::Error: Could not open " << path
125 <<
" as a directory." << std::endl;
134 Directory::operator
void* ()
136 return(_good ?
this : NULL);
161 if(!(
_dir = opendir(path.c_str())))
165 struct dirent *entry;
167 entry = readdir(
_dir);
168 entry = readdir(
_dir);
169 while((entry = readdir(
_dir)) != NULL)
170 this->push_back(entry->d_name);
177 return(std::string(getcwd(buf,1024)));
181 TRAIL_CD(
const std::string &path,std::ostream *ouf)
184 *ouf <<
"TRAIL_CD: Switching directory from "
185 <<
TRAIL_CWD() <<
" to " << path << std::endl;
186 int result = chdir(path.c_str());
188 *ouf <<
"TRAIL_CD: CWD(" <<
TRAIL_CWD() <<
")" << std::endl;
bool TRAIL_FILEEXISTS(const std::string &fname)
int TRAIL_CD(const std::string &path, std::ostream *=NULL)
std::string TRAIL_ResolveLink(const std::string &path)
bool TRAIL_ISDIR(const std::string &fname)
int open(const std::string &s="")
void TRAIL_SafeRemove(const std::string &fname, const std::string &ext)
Directory(const std::string &s="")
std::string TRAIL_CWD(void)
int TRAIL_CreateDirectory(const std::string &fname)
bool TRAIL_ISLINK(const std::string &fname)
std::string ResolveLink(const std::string &path)