#include "sys.hpp" // for libcwd #include "debug.hpp" // for libcwd #include #include #include "stringutils.h" #include "filesystem.hpp" using namespace std; int fexist(const char *filename ) { Dout(dc::utils, "fexist(const char *filename )"); Dout(dc::utils, "filename=" << filename); struct stat buffer ; if ( stat( filename, &buffer ) == 0) return 1 ; return 0 ; } int FileSize(const char *filename ) { struct stat buffer ; if ( stat( filename, &buffer ) != 0) { return 0 ; } else { return buffer.st_size; } } /** @brief create directory recursively * * usage: see MakeDirRecursively(const char *dirname) * * * @param Directory vector of hierarchy of subdirectories * @param true if absolute path, false if relative path * @return */ bool MakeDirRecursively(vector Directory, bool AbsolutePath) { string dirstring; if (AbsolutePath) { dirstring += "/"; } for (vector::iterator it=Directory.begin(); it!= Directory.end();++it) { dirstring += *it; dirstring += "/"; } // cout << "Dirstring = "<< dirstring << "\n"; if (mkdir(dirstring.c_str(),16877) != -1) { return true; } else { if (Directory.size() > 1) { vector ParentDir(Directory); ParentDir.pop_back(); if (MakeDirRecursively(ParentDir, AbsolutePath)) { return (mkdir(dirstring.c_str(),16877) != -1); } } } return false; } /** @brief create a directory. If parent directory doesn't exist, this will be created. * * @param dirname Name of directory to be created * @return */ bool MakeDirRecursively(const char *dirname) { vector Directory; bool AbsolutePath = ((dirname[0] == '/') || (dirname[0] == '\\')); Tokenize(dirname, Directory, "/\\"); return MakeDirRecursively(Directory, AbsolutePath); }