3.8.0
Freundlich's C++ toolkit
Classes | Typedefs | Functions
fcppt.filesystem

Description

Helper functions for std::filesystem.

Link to ${fcppt_filesystem_TARGET}, or to fcppt_filesystem_interface if you only need the headers.

Classes

class  fcppt::filesystem::directory_range
 A range for directory iterators. More...
 
class  fcppt::filesystem::recursive_directory_range
 A range for recursive directory iterators. More...
 

Typedefs

using fcppt::filesystem::optional_size = fcppt::optional::object< std::uintmax_t >
 Optional size. More...
 

Functions

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::optional_error_code fcppt::filesystem::create_directories_recursive (std::filesystem::path const &path)
 Tries to creates directories recursively. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::optional_error_code fcppt::filesystem::create_directory (std::filesystem::path const &path)
 Tries to create a directory. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::extension (std::filesystem::path const &path)
 Returns the extension of a path as string. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::extension_without_dot (std::filesystem::path const &path)
 Returns the extension of a path as string without the dot. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::filesystem::optional_size fcppt::filesystem::file_size (std::filesystem::path const &path)
 Returns the size of a file. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::either::object< std::error_code, fcppt::filesystem::directory_rangefcppt::filesystem::make_directory_range (std::filesystem::path const &, std::filesystem::directory_options)
 Creates a directory range. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::either::object< std::error_code, fcppt::filesystem::recursive_directory_rangefcppt::filesystem::make_recursive_directory_range (std::filesystem::path const &, std::filesystem::directory_options)
 Creates a recursive directory range. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL std::filesystem::path fcppt::filesystem::normalize (std::filesystem::path const &path)
 Normalizes a path by removing trailing slashes. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL std::size_t fcppt::filesystem::num_subpaths (std::filesystem::path const &path)
 Returns how many sub-paths a path has. More...
 
template<typename Stream >
fcppt::optional::object< Stream > fcppt::filesystem::open (std::filesystem::path const &_path, std::ios_base::openmode const _openmode)
 Opens a file, returning an optional. More...
 
template<typename Stream , typename Exception = fcppt::exception>
Stream fcppt::filesystem::open_exn (std::filesystem::path const &_path, std::ios_base::openmode const _openmode)
 Opens a file, throwing an exception on failure. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::path_to_string (std::filesystem::path const &path)
 Turns a path into an fcppt::string. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL std::filesystem::path fcppt::filesystem::remove_extension (std::filesystem::path const &path)
 Removes the extension from a path. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL std::filesystem::path fcppt::filesystem::replace_extension (std::filesystem::path const &path, fcppt::string_view const &new_extension)
 Replaces the extension of a path. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::stem (std::filesystem::path const &path)
 Returns the stem of a path as a string. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL std::filesystem::path fcppt::filesystem::strip_prefix (std::filesystem::path const &prefix, std::filesystem::path const &path)
 Strips a prefix from a path. More...
 

Typedef Documentation

◆ optional_size

Optional size.

Function Documentation

◆ create_directories_recursive()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::optional_error_code fcppt::filesystem::create_directories_recursive ( std::filesystem::path const &  path)

Tries to creates directories recursively.

Tries to create each nonexistant sub directory of path.

◆ create_directory()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::optional_error_code fcppt::filesystem::create_directory ( std::filesystem::path const &  path)

Tries to create a directory.

Tries to create the last component of path as a directory.

◆ extension()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::extension ( std::filesystem::path const &  path)

Returns the extension of a path as string.

Returns the extension of path as a string instead of a path.

Parameters
pathThe path to return the extension from
Returns
The extension as a string. If there is no extension, the string will be empty.

◆ extension_without_dot()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::extension_without_dot ( std::filesystem::path const &  path)

Returns the extension of a path as string without the dot.

Returns the extension of path without the dot as a string instead of a path.

Parameters
pathThe path to return the extension from
Returns
The extension as a string without the dot. If there is no extension, the string will be empty.

◆ file_size()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::filesystem::optional_size fcppt::filesystem::file_size ( std::filesystem::path const &  path)

Returns the size of a file.

Returns the size of path if it exists and its size can be obtained, otherwise returns the empty optional.

◆ make_directory_range()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::either::object<std::error_code, fcppt::filesystem::directory_range> fcppt::filesystem::make_directory_range ( std::filesystem::path const &  ,
std::filesystem::directory_options   
)

Creates a directory range.

◆ make_recursive_directory_range()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::either::object<std::error_code, fcppt::filesystem::recursive_directory_range> fcppt::filesystem::make_recursive_directory_range ( std::filesystem::path const &  ,
std::filesystem::directory_options   
)

Creates a recursive directory range.

◆ normalize()

FCPPT_FILESYSTEM_DETAIL_SYMBOL std::filesystem::path fcppt::filesystem::normalize ( std::filesystem::path const &  path)

Normalizes a path by removing trailing slashes.

Returns a copy of path with trailing slashes removed.

Parameters
pathThe path to remove trailing slashes from

◆ num_subpaths()

FCPPT_FILESYSTEM_DETAIL_SYMBOL std::size_t fcppt::filesystem::num_subpaths ( std::filesystem::path const &  path)

Returns how many sub-paths a path has.

Returns how many sub-path path has

Parameters
pathThe path to count the sub-paths of

◆ open()

template<typename Stream >
fcppt::optional::object<Stream> fcppt::filesystem::open ( std::filesystem::path const &  _path,
std::ios_base::openmode const  _openmode 
)

Opens a file, returning an optional.

Tries to open _path with _openmode and returns an empty optional on failure.

Template Parameters
StreamMust be a std::{basic_ifstream,basic_ofstream,basic_fstream}.

◆ open_exn()

template<typename Stream , typename Exception = fcppt::exception>
Stream fcppt::filesystem::open_exn ( std::filesystem::path const &  _path,
std::ios_base::openmode const  _openmode 
)

Opens a file, throwing an exception on failure.

Tries to open _path with _openmode and throw an exception on failure.

Template Parameters
StreamMust be a std::{basic_ifstream,basic_ofstream,basic_fstream}.
ExceptionMust be constructible from fcppt::string.

◆ path_to_string()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::path_to_string ( std::filesystem::path const &  path)

Turns a path into an fcppt::string.

Turns path into an fcppt::string.

◆ remove_extension()

FCPPT_FILESYSTEM_DETAIL_SYMBOL std::filesystem::path fcppt::filesystem::remove_extension ( std::filesystem::path const &  path)

Removes the extension from a path.

Removes the extension (inluding the dot) from path if it has any.

Parameters
pathThe path to remove the extension from
Returns
A new path with the extension removed

◆ replace_extension()

FCPPT_FILESYSTEM_DETAIL_SYMBOL std::filesystem::path fcppt::filesystem::replace_extension ( std::filesystem::path const &  path,
fcppt::string_view const &  new_extension 
)

Replaces the extension of a path.

Replaces the extension of path with new_extension.

Parameters
pathThe path to replace the extension of
new_extensionThe new extension, excluding the dot
Returns
A new path with the extension replaced

◆ stem()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::stem ( std::filesystem::path const &  path)

Returns the stem of a path as a string.

Returns the stem of path as a string. The stem is the filename excluding the extension.

Parameters
pathThe path to return the stem from
Returns
A string with the stem of the path, or an empty string if the path has no filename

◆ strip_prefix()

FCPPT_FILESYSTEM_DETAIL_SYMBOL std::filesystem::path fcppt::filesystem::strip_prefix ( std::filesystem::path const &  prefix,
std::filesystem::path const &  path 
)

Strips a prefix from a path.

Strips prefix from path.

Warning
The behavior is undefined if prefix is not a prefix of path
Parameters
prefixThe prefix path
pathThe path to strip the prefix from