Provides functions for accessing the file system.
Definition in file fs.hpp.
#include <string>
#include <unordered_map>
#include <vector>
Go to the source code of this file.
Namespaces | |
genesis | |
Container namespace for all symbols of genesis in order to keep them separate when used as a library. | |
genesis::utils | |
Functions | |
std::string | current_path () |
Return the current (working) directory, simiar to getcwd(). More... | |
void | dir_create (std::string const &path, bool with_parents=true) |
Create a directory. More... | |
bool | dir_exists (std::string const &dir) |
Return true iff the directory exists. More... | |
std::vector< std::string > | dir_list_contents (std::string const &dir, bool full_path=false, std::string const ®ex="") |
Get a list of files and directories in a directory. More... | |
std::vector< std::string > | dir_list_directories (std::string const &dir, bool full_path=false, std::string const ®ex="") |
Get a list of directories in a directory. More... | |
std::vector< std::string > | dir_list_files (std::string const &dir, bool full_path=false, std::string const ®ex="") |
Get a list of files in a directory. More... | |
std::string | dir_normalize_path (std::string const &path) |
Normalize a dir name, i.e., make sure that the given path ends with exaclty one slash. More... | |
void | file_append (std::string const &content, std::string const &filename, bool create_dirs=true) |
Append the content of a string to a file. More... | |
std::string | file_basename (std::string const &filename) |
Remove directory name from file name if present. More... | |
std::string | file_basename (std::string const &filename, std::vector< std::string > const &remove_extensions) |
Remove the directory name from a file name if present, and remove a list of given extensions. More... | |
bool | file_exists (std::string const &filename) |
Return true iff the file exists (and is in fact a file, and not, e.g., a directory). More... | |
std::string | file_extension (std::string const &filename) |
Return the extension name of a file. More... | |
std::string | file_filename (std::string const &filename) |
Remove extension if present. More... | |
std::unordered_map< std::string, std::string > | file_info (std::string const &filename) |
Return information about a file. More... | |
bool | file_is_readable (std::string const &filename) |
Return whether a file is readable. More... | |
bool | file_is_readable (std::string const &filename, std::string &err_str) |
Return whether a file is readable, and potentially store the error message. More... | |
std::string | file_path (std::string const &filename) |
Return the path leading to a file. More... | |
std::string | file_read (std::string const &filename, bool detect_compression=true) |
Return the contents of a file as a string. More... | |
std::vector< std::string > | file_read_lines (std::string const &filename, bool detect_compression=true) |
Return the contents of a file as a vector of strings, one entry for each line. More... | |
size_t | file_size (std::string const &filename) |
Return the size of a file. More... | |
void | file_write (std::string const &content, std::string const &filename, bool create_dirs=true) |
Write the content of a string to a file. More... | |
bool | is_dir (std::string const &path) |
Return true iff the provided path is a directory. More... | |
bool | is_file (std::string const &path) |
Return true iff the provided path is a (readable) file. More... | |
bool | is_valid_filename (std::string const &filename) |
Check whether a file name is valid. More... | |
bool | path_exists (std::string const &path) |
Return whether a path exists, i.e., is a file or directory. More... | |
std::string | real_path (std::string const &path, bool resolve_link=true) |
Return the real path of a file or directory, similar to realpath(). More... | |
std::string | sanitize_filename (std::string const &filename) |
Remove or replace all invalid parts of a filename. More... | |