Ase::Path namespace

The Path namespace provides functions for file path manipulation and testing.

Functions

auto abspath(const String& path, const String& incwd) →  String
auto basename(const String& path) →  String
Strips all directory components from path and returns the resulting file name.
auto cache_home() →  String
Get the $XDG_CACHE_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
auto check(const String& file, const String& mode) →  bool
auto config_dirs() →  String
Get the $XDG_CONFIG_DIRS directory list, see: https://specifications.freedesktop.org/basedir-spec/latest.
auto config_home() →  String
Get the $XDG_CONFIG_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
auto config_names() →  String
Get config names as set with config_names(), if unset defaults to program_alias().
void config_names(const String& names)
Set a colon separated list of names for this application to find configuration settings and files.
auto copy_file(const String& src, const String& dest) →  bool
Copy a file to a new non-existing location, sets errno and returns false on error.
auto cwd() →  String
Return the current working directoy, including symlinks used in $PWD if available.
auto data_dirs() →  String
Get the $XDG_DATA_DIRS directory list, see: https://specifications.freedesktop.org/basedir-spec/latest.
auto data_home() →  String
Get the $XDG_DATA_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
auto dir_terminate(const String& path) →  String
Append trailing slash to path, unless it's present.
auto dircontains(const String& dirpath, const String& descendant, String* relpath) →  bool
Check if descendant belongs to the directory hierarchy under dirpath.
auto dirname(const String& path) →  String
Retrieve the directory part of the filename path.
auto equals(const String& file1, const String& file2) →  bool
auto expand_tilde(const String& path) →  String
Expand a "~/" or "~user/" path which refers to user home directories.
auto file_size(const String& path) →  size_t
Retrieve the on-disk size in bytes of path.
void glob(const String& pathpattern, StringS& dirs, StringS& files)
Create list with directories and filenames matching pathpattern with shell wildcards.
void glob(const String& pathpattern, StringS& matches)
Create list with filenames matching pathpattern with shell wildcards.
auto isabs(const String& path) →  bool
Return wether path is an absolute pathname.
auto isdirname(const String& path) →  bool
Return wether path is pointing to a directory component.
auto isroot(const String& path, bool dos_drives) →  bool
Return wether path is an absolute pathname which identifies the root directory.
auto join_with(const String& head, char joiner, const String& tail) →  String
Construct head + joiner + tail avoiding duplicates of joiner.
auto mkdirs(const String& dirpath, uint mode) →  bool
Create the directories in dirpath with mode, check errno on false returns.
auto normalize(const String& path) →  String
Convert path to normal form.
auto realpath(const String& path) →  String
Resolve links and directory references in path and provide a canonicalized absolute pathname.
void rglob(const String& basedir, const String& pattern, StringS& matches)
Recursively match files with glob pattern under basedir.
void rmrf(const String& dir)
Recursively delete directory tree.
auto runtime_dir() →  String
Get the $XDG_RUNTIME_DIR directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
auto searchpath_contains(const String& searchpath, const String& element) →  bool
Check if searchpath contains element, a trailing slash searches for directories.
auto searchpath_find(const String& searchpath, const String& file, const String& mode) →  String
Find the first file in searchpath which matches mode (see check()).
auto searchpath_list(const String& searchpath, const String& mode) →  StringS
Find all searchpath entries matching mode (see check()).
auto searchpath_multiply(const String& searchpath, const String& postfixes) →  String
Yield a new searchpath by combining each element of searchpath with each element of postfixes.
auto simplify_abspath(const std::string& abspath_expression) →  String
Remove extra slashes, './' and '../' from abspath_expression.
auto strip_slashes(const String& path) →  String
Strip trailing directory terminators.
void unique_realpaths(StringS& pathnames)
Convert all pathnames via realpath() and eliminate duplicates.
auto user_home(const String& username) →  String
Get a user's home directory, uses $HOME if no username is given.

Function documentation

String Ase::Path::abspath(const String& path, const String& incwd)

Parameters
path a filename path
incwd optional current working directory

Complete path to become an absolute file path. If neccessary, incwd or the real current working directory is prepended.

bool Ase::Path::check(const String& file, const String& mode)

Parameters
file possibly relative filename
mode feature string
Returns true if file adhears to mode

Perform various checks on file and return whether all checks passed. On failure, errno is set appropriately, and FALSE is returned. Available features to be checked for are:

  • e - file must exist
  • r - file must be readable
  • w - file must be writable
  • x - file must be executable
  • f - file must be a regular file
  • d - file must be a directory
  • l - file must be a symbolic link
  • c - file must be a character device
  • b - file must be a block device
  • p - file must be a named pipe
  • s - file must be a socket.

bool Ase::Path::equals(const String& file1, const String& file2)

Parameters
file1 possibly relative filename
file2 possibly relative filename
Returns TRUE if file1 and file2 are equal

Check whether file1 and file2 are pointing to the same inode in the same file system on the same device.