24 #ifndef __FileHandling_hh__
25 #define __FileHandling_hh__
27 #include <bias_config.h>
35 #define DEFAULT_LEADING_ZEROS 5
52 static int RemoveDir(
const std::string &subdir);
55 static int CreateDir(
const std::string &subdir);
59 static int CreateDirRecursive(
const std::string &dir);
62 static bool FileExists(
const std::string &file);
69 static int GetDirectoryContent(
const std::string &Dir,
70 const std::string &prefix,
71 const std::string &suffix,
72 std::vector<std::string> &content,
73 const bool GetFullPath =
false);
76 static bool FileReadable(
const std::string &filename);
82 return (
remove(filename.c_str()) == 0);
89 return (rename(oldFilename.c_str(), newFilename.c_str()) == 0);
94 bool CopyFileTo(
const std::string &oldFilename,
const std::string &newFilename);
98 inline static std::string
toString(
const T thenumber,
99 int numzeros = DEFAULT_LEADING_ZEROS)
101 std::stringstream ss;
102 ss << std::setfill(
'0')<<std::setw(numzeros)<<thenumber;
115 static void SplitName(
const std::string &fullname, std::string &dir,
116 std::string &base, std::string &suffix);
119 static std::string Directory(
const std::string &fullname);
122 static std::string Basename(
const std::string &fullname);
125 static std::string Suffix(
const std::string &fullname);
128 static std::string Extension(
const std::string &fullname);
132 static std::string Filename(
const std::string &fullname);
136 static std::string DirectoryAndBasename(
const std::string &fullname);
142 static void SplitPath(
const std::string &fullpath,
143 std::vector<std::string> &result);
146 static std::string LowerCase(
const std::string &input);
149 static std::string UpperCase(
const std::string &input);
153 static void LogCommandLine(
int argc,
char** argv, std::ostream &os);
157 static void LogCommandLine(
int argc,
char** argv,
const std::string & filename);
161 static std::string LeadingZeroString(
const int &n,
162 const unsigned int &digits=DEFAULT_LEADING_ZEROS);
166 static std::string CurrentDateTimeString();
170 static int ExtractNumberFromRight(
const std::string &inStr,
171 int &number,
int &posL,
int &posR );
191 static int FilenameSequence(
const std::string &refFileName,
192 std::string &resultFilename,
193 const int &offsetFromRef,
194 const unsigned int &stepsize = 1);
199 static int FilenameExpansion(
const std::string &in, std::string &out);
202 static std::string GetCwd();
205 static int ChDir(
const std::string &dir);
209 static std::string GetApplicationPath();
212 static bool IsAbsolute(
const std::string &path);
217 if (thepath.empty())
return thepath;
220 std::string::size_type poslastslash = thepath.rfind(
'\\');
222 std::string::size_type poslastslash = thepath.rfind(
'/');
224 if (poslastslash == thepath.size()-1) {
226 return thepath.substr(0, poslastslash);
236 std::string result = thepath;
238 const std::string delimiter =
"\\";
239 const std::string toReplace =
"/";
241 const std::string delimiter =
"/";
242 const std::string toReplace =
"\\";
244 std::string::size_type pos = result.find_first_of(toReplace);
245 while (pos != std::string::npos) {
246 result.replace(pos, 1, delimiter);
247 pos = result.find_first_of(toReplace, pos+1);
255 static char ToLower_c(
char c);
258 static char ToUpper_c(
char c);
264 #endif // __FileHandling_hh__
static bool MoveOrRenameFile(const std::string &oldFilename, const std::string &newFilename)
Renames or moves the file with the given name.
static std::string toString(const T thenumber, int numzeros=DEFAULT_LEADING_ZEROS)
Converts number to string with leading zeros.
static std::string CorrectSlashes(const std::string &thepath)
Replace wrong slashes with respect to current operating system.
static bool RemoveFile(const std::string &filename)
Removes the file with the given name.
Functions to create, check and delete files and to handle file names, such as splitting into director...
static std::string StripTerminatingSlash(const std::string &thepath)
Remove a trailing slash from the path if there is one.