Limo
A simple mod manager
Loading...
Searching...
No Matches
path_utils Namespace Reference

Contains utility functions for dealing with std::filesystem::path objects. More...

Functions

std::optional< sfs::path > pathExists (const sfs::path &path_to_check, const sfs::path &base_path, bool case_insensitive)
 
std::string toLowerCase (const sfs::path &path)
 
void moveFilesToDirectory (const sfs::path &source, const sfs::path &destination, bool move)
 
std::string normalizePath (const std::string &path)
 Replaces all double backslash path separators with a forward slash.
 
std::string getRelativePath (sfs::path target, sfs::path source)
 
bool directoryIsEmpty (const sfs::path &directory, std::vector< std::string > ignored_files)
 
int getPathLength (const sfs::path &path)
 
std::pair< sfs::path, sfs::path > removePathComponents (const sfs::path &path, int depth)
 
void renameFiles (const sfs::path &destination, const sfs::path &source, std::function< unsigned char(unsigned char)> converter)
 
void moveFilesWithDepth (const sfs::path &source, const sfs::path &destination, int depth)
 
void copyOrMoveFiles (const sfs::path &source, const sfs::path &destination, bool move)
 
bool exists (const std::filesystem::path &path)
 Checks whether the given path exists. This differs from std::filesystem::exists in that true is returned even if path points to an invalid symlink.
 
std::optional< std::filesystem::path > pathExists (const std::filesystem::path &path_to_check, const std::filesystem::path &base_path, bool case_insensitive=true)
 Checks if the target path exists.
 
std::string toLowerCase (const std::filesystem::path &path)
 Returns a string containing the given path in lower case.
 
void moveFilesToDirectory (const std::filesystem::path &source, const std::filesystem::path &destination, bool move=true)
 Recursively moves all files from the source directory to the target directory.
 
std::string getRelativePath (std::filesystem::path target, std::filesystem::path source)
 Determines the relative path from source to target. Only works if source.string() is a sub-string of target.string().
 
bool directoryIsEmpty (const std::filesystem::path &directory, std::vector< std::string > ignored_files={})
 Returns true if directory is empty or contains only empty directories.
 
int getPathLength (const std::filesystem::path &path)
 Returns the number of elements in given path.
 
std::pair< std::filesystem::path, std::filesystem::path > removePathComponents (const std::filesystem::path &path, int depth)
 Removes the first components of a given path.
 
void renameFiles (const std::filesystem::path &destination, const std::filesystem::path &source, std::function< unsigned char(unsigned char)> converter)
 Recursively renames all files at given source directory using given converter, then copies the result to given destination directory.
 
void moveFilesWithDepth (const std::filesystem::path &source, const std::filesystem::path &destination, int depth)
 Recursively moves all files from source to destination, removes all path components with depth < root_level.
 
void copyOrMoveFiles (const std::filesystem::path &source, const std::filesystem::path &destination, bool move)
 Copies or moves files from source to dest.
 

Detailed Description

Contains utility functions for dealing with std::filesystem::path objects.

Function Documentation

◆ copyOrMoveFiles()

void path_utils::copyOrMoveFiles ( const std::filesystem::path & source,
const std::filesystem::path & destination,
bool move )

Copies or moves files from source to dest.

Parameters
sourceCopy/ move source path.
destinationCopy/ move target path.
moveIf true: Move files, else: Recursively copy files.

◆ directoryIsEmpty()

bool path_utils::directoryIsEmpty ( const std::filesystem::path & directory,
std::vector< std::string > ignored_files = {} )

Returns true if directory is empty or contains only empty directories.

Parameters
directoryDirectory to check.
ignored_filesVector of file names to ignore.
Returns
True if empty, else false.

◆ exists()

bool path_utils::exists ( const std::filesystem::path & path)

Checks whether the given path exists. This differs from std::filesystem::exists in that true is returned even if path points to an invalid symlink.

Parameters
pathPath to check.
Returns
True if path exists.

◆ getPathLength()

int path_utils::getPathLength ( const std::filesystem::path & path)

Returns the number of elements in given path.

Parameters
pathPath to be checked.
Returns
The length.

◆ getRelativePath()

std::string path_utils::getRelativePath ( std::filesystem::path target,
std::filesystem::path source )

Determines the relative path from source to target. Only works if source.string() is a sub-string of target.string().

Parameters
targetTarget path.
sourceSource path.
Returns
The relative path.

◆ moveFilesToDirectory()

void path_utils::moveFilesToDirectory ( const std::filesystem::path & source,
const std::filesystem::path & destination,
bool move = true )

Recursively moves all files from the source directory to the target directory.

Parameters
sourceSource directory.
destinationTarget directory.
moveIf false: Copy files instead of moving them.

◆ moveFilesWithDepth()

void path_utils::moveFilesWithDepth ( const std::filesystem::path & source,
const std::filesystem::path & destination,
int depth )

Recursively moves all files from source to destination, removes all path components with depth < root_level.

Parameters
sourceSource path.
destinationDestination path.
depthMinimum depth for path components to keep.

◆ normalizePath()

std::string path_utils::normalizePath ( const std::string & path)

Replaces all double backslash path separators with a forward slash.

Returns
The normalized path.

◆ pathExists()

std::optional< std::filesystem::path > path_utils::pathExists ( const std::filesystem::path & path_to_check,
const std::filesystem::path & base_path,
bool case_insensitive = true )

Checks if the target path exists.

Parameters
targetPath to check.
base_pathIf specified, target path is appended to this path during the search.
case_insensitiveIf true: Ignore case mismatch for path search.
Returns
The target path in its actual case, if found.

◆ removePathComponents()

std::pair< std::filesystem::path, std::filesystem::path > path_utils::removePathComponents ( const std::filesystem::path & path,
int depth )

Removes the first components of a given path.

Parameters
pathSource path.
depthComponents with depth < this will be removed.
Returns
A pair of the removed components and the shortened path.

◆ renameFiles()

void path_utils::renameFiles ( const std::filesystem::path & destination,
const std::filesystem::path & source,
std::function< unsigned char(unsigned char)> converter )

Recursively renames all files at given source directory using given converter, then copies the result to given destination directory.

Parameters
destinationPath to destination directory for renamed files.
sourcePath to source files to be renamed.
converterFunction which converts one char to another, e.g. converting to upper case.

◆ toLowerCase()

std::string path_utils::toLowerCase ( const std::filesystem::path & path)

Returns a string containing the given path in lower case.

Parameters
pathPath to be converted.
Returns
The lower case path.