SpECTRE
v2025.03.17
|
A light-weight file system library. More...
Namespaces | |
namespace | file_system |
A light-weight file system library based on POSIX. | |
Functions | |
void | file_system::copy (const std::string &from, const std::string &to) |
Copies files or directories. More... | |
std::string | file_system::cwd () |
Returns the current working directory, resolving symlinks. | |
void | file_system::create_directory (const std::string &dir, double wait_time=1, size_t num_tries=40) |
Creates a directory, including any parents that don't exist. If the directory exists create_directory does nothing. More... | |
bool | file_system::check_if_dir_exists (const std::string &dir) |
Returns true if the directory exists. More... | |
bool | file_system::check_if_file_exists (const std::string &file) |
Returns true if the regular file or link to the regular file exists. More... | |
size_t | file_system::file_size (const std::string &file) |
Returns the file size in bytes. More... | |
std::string | file_system::get_absolute_path (const std::string &rel_path) |
Get the absolute path, resolving symlinks. More... | |
std::string | file_system::get_file_name (const std::string &file_path) |
Given a path to a file returns the file name. More... | |
std::string | file_system::get_parent_path (const std::string &path) |
Wraps the dirname function to get the pathname of the parent directory. More... | |
std::vector< std::string > | file_system::glob (const std::string &pattern) |
Get a list of files matching the given glob pattern. | |
bool | file_system::is_file (const std::string &path) |
Returns true if the path points to a regular file or a link to a regular file. More... | |
std::vector< std::string > | file_system::ls (const std::string &dir_name="./") |
Gets a list of files in a directory. More... | |
void | file_system::rm (const std::string &path, bool recursive) |
Deletes a file or directory. More... | |
A light-weight file system library.
bool file_system::check_if_dir_exists | ( | const std::string & | dir | ) |
Returns true if the directory exists.
Returns: true
if the directory exists
bool file_system::check_if_file_exists | ( | const std::string & | file | ) |
Returns true if the regular file or link to the regular file exists.
Returns: true
if the file exists
void file_system::copy | ( | const std::string & | from, |
const std::string & | to | ||
) |
Copies files or directories.
Wrapper around std::file_system::copy()
.
void file_system::create_directory | ( | const std::string & | dir, |
double | wait_time = 1 , |
||
size_t | num_tries = 40 |
||
) |
Creates a directory, including any parents that don't exist. If the directory exists create_directory
does nothing.
Requires: permissions to create dir
on the filesystem
Effects: creates the directory dir
on the filesystem
dir | the path where to create the directory |
wait_time | time to wait in seconds between failures |
num_tries | number of attempts to create directory (for slow filesystems) |
size_t file_system::file_size | ( | const std::string & | file | ) |
Returns the file size in bytes.
Requires: file
is a valid file on the filesystem
Returns: size of file
in bytes
std::string file_system::get_absolute_path | ( | const std::string & | rel_path | ) |
Get the absolute path, resolving symlinks.
Requires: rel_path
is a valid path on the filesystem
Returns: the absolute path
std::string file_system::get_file_name | ( | const std::string & | file_path | ) |
Given a path to a file returns the file name.
Requires: file_path
is a valid path on the filesystem
Returns: the file name
std::string file_system::get_parent_path | ( | const std::string & | path | ) |
Wraps the dirname function to get the pathname of the parent directory.
See the opengroup documentation: http://pubs.opengroup.org/onlinepubs/9699919799/functions/dirname.html
Requires: path
is a valid path on the filesystem
Returns: the path to the parent directory
bool file_system::is_file | ( | const std::string & | path | ) |
Returns true if the path points to a regular file or a link to a regular file.
Requires: path
is a valid path on the filesystem
Returns: true
if file
is a file, not a directory
std::vector< std::string > file_system::ls | ( | const std::string & | dir_name = "./" | ) |
Gets a list of files in a directory.
Returns: vector of all files and directories inside dir_name
void file_system::rm | ( | const std::string & | path, |
bool | recursive | ||
) |
Deletes a file or directory.
Requires: path
be a valid path on the filesystem
Effects: deletes path
from the filesystem, if recursive
is true
then behaves like rm -r
, otherwise like rm
but will delete an empty directory