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

Description

Helper functions for boost::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...
 

Functions

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::system::optional_error_code fcppt::filesystem::create_directories_recursive (boost::filesystem::path const &path) FCPPT_PP_WARN_UNUSED_RESULT
 Tries to creates directories recursively. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::system::optional_error_code fcppt::filesystem::create_directory (boost::filesystem::path const &path) FCPPT_PP_WARN_UNUSED_RESULT
 Tries to create a directory. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::create_directory_error (boost::filesystem::path const &path, boost::system::error_code error)
 Returns an error string for a failed create directory operation. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::extension (boost::filesystem::path const &path)
 Returns the extension of a path as string. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::extension_without_dot (boost::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 (boost::filesystem::path const &path)
 Returns the size of a file. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL boost::filesystem::path fcppt::filesystem::normalize (boost::filesystem::path const &path)
 Normalizes a path by removing trailing slashes. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL std::size_t fcppt::filesystem::num_subpaths (boost::filesystem::path const &path)
 Returns how many sub-paths a path has. More...
 
template<typename Stream >
fcppt::optional::object< Stream > fcppt::filesystem::open (boost::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 (boost::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 (boost::filesystem::path const &path)
 Turns a path into an fcppt::string. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL boost::filesystem::path fcppt::filesystem::remove_extension (boost::filesystem::path const &path)
 Removes the extension from a path. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL boost::filesystem::path fcppt::filesystem::replace_extension (boost::filesystem::path const &path, fcppt::string const &new_extension)
 Replaces the extension of a path. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::stem (boost::filesystem::path const &path)
 Returns the stem of a path as a string. More...
 
FCPPT_FILESYSTEM_DETAIL_SYMBOL boost::filesystem::path fcppt::filesystem::strip_prefix (boost::filesystem::path const &prefix, boost::filesystem::path const &path)
 Strips a prefix from a path. More...
 

Function Documentation

◆ create_directories_recursive()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::system::optional_error_code fcppt::filesystem::create_directories_recursive ( boost::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::system::optional_error_code fcppt::filesystem::create_directory ( boost::filesystem::path const &  path)

Tries to create a directory.

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

◆ create_directory_error()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::create_directory_error ( boost::filesystem::path const &  path,
boost::system::error_code  error 
)

Returns an error string for a failed create directory operation.

◆ extension()

FCPPT_FILESYSTEM_DETAIL_SYMBOL fcppt::string fcppt::filesystem::extension ( boost::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 ( boost::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 ( boost::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.

◆ normalize()

FCPPT_FILESYSTEM_DETAIL_SYMBOL boost::filesystem::path fcppt::filesystem::normalize ( boost::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 ( boost::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 ( boost::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 ( boost::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 ( boost::filesystem::path const &  path)

Turns a path into an fcppt::string.

Turns path into an fcppt::string.

◆ remove_extension()

FCPPT_FILESYSTEM_DETAIL_SYMBOL boost::filesystem::path fcppt::filesystem::remove_extension ( boost::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 boost::filesystem::path fcppt::filesystem::replace_extension ( boost::filesystem::path const &  path,
fcppt::string 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 ( boost::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 boost::filesystem::path fcppt::filesystem::strip_prefix ( boost::filesystem::path const &  prefix,
boost::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