Hermes
hermes::FileSystem Class Reference

Set of useful functions to manipulate files and directories. More...

Static Public Member Functions

static std::vector< std::string > basename (const std::vector< std::string > &paths, const std::string &suffix="")
 Strips directory and suffix from filenames. More...
 
static std::string basename (const std::string &path, const std::string &suffix="")
 Strips directory and suffix from filename. More...
 
static std::string fileExtension (const std::string &filename)
 Retrieves file's extension. More...
 
static std::string normalizePath (const std::string &path, bool with_backslash=false)
 Fixes path separators and ".." parts. More...
 
static u64 readFile (const char *filename, char **text)
 loads contents from file More...
 
static std::vector< unsigned char > readBinaryFile (const Path &filename)
 loads binary content from file More...
 
static std::vector< std::string > readLines (const Path &path)
 Read file's contents separated by line breaks. More...
 
static std::string readFile (const Path &filename)
 Read ascii contents from file. More...
 
static bool touch (const Path &path_to_file)
 Creates an empty file or access it. More...
 
static u64 writeFile (const Path &path, const std::vector< char > &content, bool is_binary=false)
 Writes content to file. More...
 
static u64 writeFile (const Path &path, const std::string &content, bool is_binary=false)
 Writes content to file. More...
 
static u64 writeLine (const Path &path, const std::string &line, bool is_binary=false)
 Writes line to path. More...
 
static u64 appendToFile (const Path &path, const std::vector< char > &content, bool is_binary=false)
 Appends content to file. More...
 
static u64 appendToFile (const Path &path, const std::string &content, bool is_binary=false)
 Appends content to file. More...
 
static u64 appendLine (const Path &path, const std::string &line, bool is_binary=false)
 Appends line to file. More...
 
static bool fileExists (const Path &path)
 Checks if file exists. More...
 
static bool isFile (const Path &path)
 Checks if filename corresponds to a file. More...
 
static bool isDirectory (const Path &dir_name)
 Checks if dir_name corresponds to a directory. More...
 
static std::vector< Pathls (const Path &path, ls_options options=ls_options::none)
 Lists files inside a directory. More...
 
static bool mkdir (const Path &path)
 Recursively creates the path of directories. More...
 
static bool copyFile (const Path &source, const Path &destination)
 Copy file's contents to destination file. More...
 
static std::vector< Pathfind (const Path &path, const std::string &pattern, find_options options=find_options::none)
 Search for files in a directory hierarchy. More...
 

Detailed Description

Set of useful functions to manipulate files and directories.

Member Function Documentation

◆ appendLine()

u64 hermes::FileSystem::appendLine ( const Path path,
const std::string &  line,
bool  is_binary = false 
)
static

Appends line to file.

Parameters
path
line
is_binary
Returns

◆ appendToFile() [1/2]

u64 hermes::FileSystem::appendToFile ( const Path path,
const std::string &  content,
bool  is_binary = false 
)
static

Appends content to file.

Parameters
path[in] path/to/file.ext
content
is_binary[in | default = false] write in binary mode
Returns
number of bytes successfully written.

◆ appendToFile() [2/2]

u64 hermes::FileSystem::appendToFile ( const Path path,
const std::vector< char > &  content,
bool  is_binary = false 
)
static

Appends content to file.

Parameters
path[in] path/to/file.ext
content
is_binary[in | default = false] write in binary mode
Returns
number of bytes successfully written.

◆ basename() [1/2]

std::string hermes::FileSystem::basename ( const std::string &  path,
const std::string &  suffix = "" 
)
static

Strips directory and suffix from filename.

Parameters
path[in] /path/to/filename<suffix>
suffix[in | optional]
Returns
filename

◆ basename() [2/2]

std::vector< std::string > hermes::FileSystem::basename ( const std::vector< std::string > &  paths,
const std::string &  suffix = "" 
)
static

Strips directory and suffix from filenames.

Parameters
paths[in] {/path/to/filename1suffix,...}
suffix[in | optional]
Returns
{filename1, filename2, ...}

◆ copyFile()

bool hermes::FileSystem::copyFile ( const Path source,
const Path destination 
)
static

Copy file's contents to destination file.

Parameters
source
destination
Returns

◆ fileExists()

bool hermes::FileSystem::fileExists ( const Path path)
static

Checks if file exists.

Parameters
path/path/to/file.ext
Returns
true if file exists

◆ fileExtension()

std::string hermes::FileSystem::fileExtension ( const std::string &  filename)
static

Retrieves file's extension.

Parameters
filenamepath/to/filename.extension
Returns
file's extension, if any (after last '.')

◆ find()

std::vector< Path > hermes::FileSystem::find ( const Path path,
const std::string &  pattern,
find_options  options = find_options::none 
)
static

Search for files in a directory hierarchy.

Parameters
pathroot directory
pattern[in | ""] regular expression
options[in | find_options::none] none = default behaviour; recursive = recursively search on directories bellow path
Returns

◆ isDirectory()

bool hermes::FileSystem::isDirectory ( const Path dir_name)
static

Checks if dir_name corresponds to a directory.

Parameters
dir_name[in] /path/to/directory
Returns
true if dir_name points to a directory.

◆ isFile()

bool hermes::FileSystem::isFile ( const Path path)
static

Checks if filename corresponds to a file.

Parameters
path/path/to/file.ext
Returns
true if filename points to a file.

◆ ls()

std::vector< Path > hermes::FileSystem::ls ( const Path path,
ls_options  options = ls_options::none 
)
static

Lists files inside a directory.

Parameters
path[in] path/to/directory
options[in | ls_options::none] options_ based on ls command: none = the default behaviour; sort = sort paths following lexicographical order; reverse_sort = sort in reverse order; directories = list only directories; files = list only files; group_directories_first = directories come first in sorting; recursive = list directories contents;
Returns
list of paths

◆ mkdir()

bool hermes::FileSystem::mkdir ( const Path path)
static

Recursively creates the path of directories.

Parameters
pathpath/to/directory
Returns
true on success success

◆ normalizePath()

std::string hermes::FileSystem::normalizePath ( const std::string &  path,
bool  with_backslash = false 
)
static

Fixes path separators and ".." parts.

Parameters
path
with_backslash
Returns

◆ readBinaryFile()

std::vector< unsigned char > hermes::FileSystem::readBinaryFile ( const Path filename)
static

loads binary content from file

Parameters
filename[in] path/to/file.ext
Returns
vector of bytes read

◆ readFile() [1/2]

u64 hermes::FileSystem::readFile ( const char *  filename,
char **  text 
)
static

loads contents from file

Parameters
filename[in] path/to/file.
text[out] receives file content.
Returns
number of bytes successfully read.

◆ readFile() [2/2]

std::string hermes::FileSystem::readFile ( const Path filename)
static

Read ascii contents from file.

Parameters
filenamepath/to/file.ext
Returns
file's content

◆ readLines()

std::vector< std::string > hermes::FileSystem::readLines ( const Path path)
static

Read file's contents separated by line breaks.

Parameters
path
Returns

◆ touch()

bool hermes::FileSystem::touch ( const Path path_to_file)
static

Creates an empty file or access it.

Parameters
path_to_filevalid file path
Returns
true if success

◆ writeFile() [1/2]

u64 hermes::FileSystem::writeFile ( const Path path,
const std::string &  content,
bool  is_binary = false 
)
static

Writes content to file.

Parameters
path[in] path/to/file.ext
content
is_binary[in | default = false] write in binary mode
Returns
number of bytes successfully written.

◆ writeFile() [2/2]

u64 hermes::FileSystem::writeFile ( const Path path,
const std::vector< char > &  content,
bool  is_binary = false 
)
static

Writes content to file.

Parameters
path[in] path/to/file.ext
content
is_binary[in | default = false] write in binary mode
Returns
number of bytes successfully written.

◆ writeLine()

u64 hermes::FileSystem::writeLine ( const Path path,
const std::string &  line,
bool  is_binary = false 
)
static

Writes line to path.

Parameters
path
line
is_binary
Returns

The documentation for this class was generated from the following files: