rcpputils
master
C++ API providing common utilities and data structures.
|
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 | create_temp_directory (const std::string &base_name, const path &parent_path=temp_directory_path()) |
Construct a uniquely named temporary directory, in "parent", with format base_nameXXXXXX. 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... | |
bool | operator== (const path &a, const path &b) |
Compare two paths for equality. More... | |
bool | operator!= (const path &a, const path &b) |
std::ostream & | operator<< (std::ostream &os, const path &p) |
Convert the path to a string for ostream usage, such as in logging or string formatting. More... | |
|
noexcept |
Check if the path is a regular file.
p | The path to check |
|
noexcept |
Check if the path is a directory.
p | The path to check |
uint64_t rcpputils::fs::file_size | ( | const path & | p | ) |
Get the file size of the path.
p | The path to get the file size of. |
std::sytem_error |
bool rcpputils::fs::exists | ( | const path & | path_to_check | ) |
Check if a path exists.
path_to_check | The path to check. |
path rcpputils::fs::temp_directory_path | ( | ) |
Get a path to a location in the temporary directory, if it's available.
This does not create any directories. On Windows, this uses "GetTempPathA" On non-Windows, this prefers the environment variable TMPDIR, falling back to /tmp
path rcpputils::fs::create_temp_directory | ( | const std::string & | base_name, |
const path & | parent_path = temp_directory_path() |
||
) |
Construct a uniquely named temporary directory, in "parent", with format base_nameXXXXXX.
The output, if successful, is guaranteed to be a newly-created directory. The underlying implementation keeps generating paths until one that does not exist is found. This guarantees that there will be no existing files in the returned directory.
base_name | User-specified portion of the created directory |
parent | The parent path of the directory that will be created |
std::system_error | If any OS APIs do not succeed. |
path rcpputils::fs::current_path | ( | ) |
Return current working directory.
std::system_error |
bool rcpputils::fs::create_directories | ( | const path & | p | ) |
Create a directory with the given path p.
This builds directories recursively and will skip directories if they are already created.
bool rcpputils::fs::remove | ( | const path & | p | ) |
Remove the file or directory at the path p.
p | The path of the object to remove. |
bool rcpputils::fs::remove_all | ( | const path & | p | ) |
Remove the directory at the path p and its content.
Additionally to
The | path of the directory to remove. |
Remove extension(s) from a path.
An extension is defined as text starting from the end of a path to the first period (.) character.
file_path | The file path string. |
n_times | The number of extensions to remove if there are multiple extensions. |
Compare two paths for equality.
bool rcpputils::fs::operator!= | ( | const path & | a, |
const path & | b | ||
) |
std::ostream& rcpputils::fs::operator<< | ( | std::ostream & | os, |
const path & | p | ||
) |
Convert the path to a string for ostream usage, such as in logging or string formatting.
os | The stream to send the path string to |
p | The path to stringify |