rcpputils  master
C++ API providing common utilities and data structures.
Classes | Functions
rcpputils::fs Namespace Reference

Classes

class  path
 Drop-in replacement for std::filesystem::path. More...
 

Functions

bool is_regular_file (const path &p) noexcept
 Check if the path is a regular file. More...
 
bool is_directory (const path &p) noexcept
 Check if the path is a directory. More...
 
uint64_t file_size (const path &p)
 Get the file size of the path. More...
 
bool exists (const path &path_to_check)
 Check if a path exists. More...
 
path temp_directory_path ()
 Get a path to a location in the temporary directory, if it's available. More...
 
path current_path ()
 Return current working directory. More...
 
bool create_directories (const path &p)
 Create a directory with the given path p. More...
 
bool remove (const path &p)
 Remove the file or directory at the path p. More...
 
bool remove_all (const path &p)
 Remove the directory at the path p and its content. More...
 
path remove_extension (const path &file_path, int n_times=1)
 Remove extension(s) from a path. More...
 

Function Documentation

◆ is_regular_file()

bool rcpputils::fs::is_regular_file ( const path p)
inlinenoexcept

Check if the path is a regular file.

Parameters
pThe path to check
Returns
True if the path exists, false otherwise.

◆ is_directory()

bool rcpputils::fs::is_directory ( const path p)
inlinenoexcept

Check if the path is a directory.

Parameters
pThe path to check
Returns
True if the path is an existing directory, false otherwise.

◆ file_size()

uint64_t rcpputils::fs::file_size ( const path p)
inline

Get the file size of the path.

Parameters
pThe path to get the file size of.
Returns
The file size in bytes.
Exceptions
std::sytem_error

◆ exists()

bool rcpputils::fs::exists ( const path path_to_check)
inline

Check if a path exists.

Parameters
path_to_checkThe path to check.
Returns
True if the path exists, false otherwise.

◆ temp_directory_path()

path rcpputils::fs::temp_directory_path ( )
inline

Get a path to a location in the temporary directory, if it's available.

Returns
A path to a directory for storing temporary files and directories.

◆ current_path()

path rcpputils::fs::current_path ( )
inline

Return current working directory.

Returns
The current working directory.
Exceptions
std::system_error

◆ create_directories()

bool rcpputils::fs::create_directories ( const path p)
inline

Create a directory with the given path p.

This builds directories recursively and will skip directories if they are already created.

Returns
Return true if the directory is created, false otherwise.

◆ remove()

bool rcpputils::fs::remove ( const path p)
inline

Remove the file or directory at the path p.

Parameters
pThe path of the object to remove.
Returns
true if the file exists and it was successfully removed, false otherwise.

◆ remove_all()

bool rcpputils::fs::remove_all ( const path p)
inline

Remove the directory at the path p and its content.

Additionally to

See also
remove, remove_all removes a directory and its containing files.
Parameters
Thepath of the directory to remove.
Returns
true if the directory exists and it was successfully removed, false otherwise.

◆ remove_extension()

path rcpputils::fs::remove_extension ( const path file_path,
int  n_times = 1 
)
inline

Remove extension(s) from a path.

An extension is defined as text starting from the end of a path to the first period (.) character.

Parameters
file_pathThe file path string.
n_timesThe number of extensions to remove if there are multiple extensions.
Returns
The path object.