irccd  3.0.3
Functions
irccd::fs_util Namespace Reference

Filesystem utilities. More...

Functions

auto base_name (const std::string &path) -> std::string
 
auto dir_name (const std::string &path) -> std::string
 
template<typename Predicate >
auto find_if (const std::string &base, bool recursive, Predicate &&predicate) -> std::string
 
auto find (const std::string &base, const std::string &name, bool recursive=false) -> std::string
 
auto find (const std::string &base, const std::regex &regex, bool recursive=false) -> std::string
 

Detailed Description

Filesystem utilities.

Function Documentation

◆ base_name()

auto irccd::fs_util::base_name ( const std::string &  path) -> std::string

Get the base name from a path.

Example, base_name("/etc/foo.conf") returns foo.conf

Parameters
paththe path
Returns
the base name

◆ dir_name()

auto irccd::fs_util::dir_name ( const std::string &  path) -> std::string

Get the parent directory from a path.

Example, dir_name("/etc/foo.conf") returns /etc

Parameters
paththe path
Returns
the parent directory

◆ find() [1/2]

auto irccd::fs_util::find ( const std::string &  base,
const std::regex &  regex,
bool  recursive = false 
) -> std::string

Overload by regular expression.

Parameters
basethe base directory
regexthe regular expression
recursivetrue to do recursive search
Returns
the full path name to the file or empty string if never found
Exceptions
boost::system::system_erroron errors

◆ find() [2/2]

auto irccd::fs_util::find ( const std::string &  base,
const std::string &  name,
bool  recursive = false 
) -> std::string

Find a file by name recursively.

Parameters
basethe base directory
namethe file name
recursivetrue to do recursive search
Returns
the full path name to the file or empty string if never found
Exceptions
boost::system::system_erroron errors

◆ find_if()

template<typename Predicate >
auto irccd::fs_util::find_if ( const std::string &  base,
bool  recursive,
Predicate &&  predicate 
) -> std::string

Search an item recursively.

The predicate must have the following signature: void f(const boost::filesystem::directory_entry& entry)

Where:

  • base is the current parent directory in the tree
  • entry is the current entry
Parameters
basethe base directory
predicatethe predicate
recursivetrue to do recursive search
Returns
the full path name to the file or empty string if never found
Exceptions
boost::system::system_erroron errors