9 #ifndef _STRUS_BASE_FILE_IO_HPP_INCLUDED
10 #define _STRUS_BASE_FILE_IO_HPP_INCLUDED
22 int readFileSize(
const std::string& filename, std::size_t& size);
28 int readFile(
const std::string& filename, std::string& res);
39 int writeFile(
const std::string& filename,
const std::string& content);
45 int appendFile(
const std::string& filename,
const std::string& content);
51 int removeFile(
const std::string& filename,
bool fail_ifnofexist=
false);
57 int removeDir(
const std::string& dirname,
bool fail_ifnofexist=
false);
69 int renameFile(
const std::string& old_filename,
const std::string& new_filename);
75 int createDir(
const std::string& dirname,
bool fail_ifexist=
true);
80 int mkdirp(
const std::string& dirname);
85 int changeDir(
const std::string& dirname);
92 int readDirFiles(
const std::string& path,
const std::string& ext, std::vector<std::string>& res);
98 int readDirSubDirs(
const std::string& path, std::vector<std::string>& res);
104 int readDirItems(
const std::string& path, std::vector<std::string>& res);
110 int expandFilePattern(
const std::string& pathPattern, std::vector<std::string>& res);
115 bool isFile(
const std::string& path);
120 bool isDir(
const std::string& path);
147 int getParentPath(
const std::string& path, std::string& dest);
154 int getAncestorPath(
const std::string& path,
int level, std::string& dest);
160 int getFileName(
const std::string& path, std::string& dest,
bool withExtension=
true);
181 std::string
joinFilePath(
const std::string& parentpath,
const std::string& childpath);
int renameFile(const std::string &old_filename, const std::string &new_filename)
Moves (renames) a file.
bool isFile(const std::string &path)
Check if a file system path points to a file.
int readFile(const std::string &filename, std::string &res)
Reads the complete content of a file to a string.
bool isExplicitPath(const std::string &path)
Check if a file path is explicit (relative path or absolute path)
int appendFile(const std::string &filename, const std::string &content)
Appends a string to a file creating the file if it does not exist.
int getAncestorPath(const std::string &path, int level, std::string &dest)
Get an ancestor (containing) path of a file or directory.
int readFileSize(const std::string &filename, std::size_t &size)
Evaluate the size of a file in bytes.
int createDir(const std::string &dirname, bool fail_ifexist=true)
Creates a directory if it does not exist yet.
int writeFile(const std::string &filename, const std::string &content)
Writes a string to a file creating the file if it does not exist.
int removeDir(const std::string &dirname, bool fail_ifnofexist=false)
Removes an empty directory.
int resolveUpdirReferences(std::string &path)
Resolve upper directory references in a path, e.g. replace "/home/john/../jack" by "/home/jack"...
char dirSeparator()
Get the OS path element separator.
bool isRelativePath(const std::string &path)
Check if a file system path is a path starting with a name and not with a directive referencing the c...
bool isTextFile(const std::string &path)
Check if a file system path points to a file with text content (not binary)
int readDirSubDirs(const std::string &path, std::vector< std::string > &res)
Reads all subdirectories of a directory to an array of strings.
int readStdin(std::string &res)
Reads the complete input of stdin to a string.
bool isAbsolutePath(const std::string &path)
Check if a file system path is a path starting the file system root '/'.
int expandFilePattern(const std::string &pathPattern, std::vector< std::string > &res)
Get all items matching a file path pattern (with '?' and '*' as substitutes)
int readDirFiles(const std::string &path, const std::string &ext, std::vector< std::string > &res)
Reads all file names matching to the extension ext of a directory to an array of strings.
int getFileName(const std::string &path, std::string &dest, bool withExtension=true)
Get the file name without parent path of a file or directory.
bool isDir(const std::string &path)
Check if a file system path points to a directory.
bool hasUpdirReference(const std::string &path)
Return true, if the path contains an upper directory reference '..'.
int removeDirRecursive(const std::string &dirname, bool fail_ifnofexist=false)
Removes a directory with all its contents.
int removeFile(const std::string &filename, bool fail_ifnofexist=false)
Removes a file.
int changeDir(const std::string &dirname)
Change current directory of the process.
int getFileExtension(const std::string &path, std::string &ext)
Get the extension (including '.') of a file or directory.
int readDirItems(const std::string &path, std::vector< std::string > &res)
Reads all items (directory or file) of a directory to an array of strings.
int mkdirp(const std::string &dirname)
Creates a directory path (mkdir -p)
int getParentPath(const std::string &path, std::string &dest)
Get the parent (containing) path of a file or directory.
std::string joinFilePath(const std::string &parentpath, const std::string &childpath)
Join two path with directory separator.