Skip to content

FilesystemUtils

Functions

Name
boolanyEquivalent(const fs::path & path1, const fs::path & path2)<br>Compares two paths either using equivalent() or weaklyEquivalent().
boolcopy(const fs::path & from, const fs::path & to, const fs::copy_options options =fs::copy_options::overwrite_existing
boolcopyFile(const fs::path & from, const fs::path & to, const fs::copy_options options =fs::copy_options::overwrite_existing)<br>Copy file to a location.
boolcopyToDir(const fs::path & from, const fs::path & toDir, const fs::copy_options options =fs::copy_options::overwrite_existing
booldeleteFileOrDir(const fs::path & path, bool deleteEmptyFolders =false)<br>Remove the specified file or directories.
boolequivalent(const fs::path & path1, const fs::path & path2)<br>Compare two paths with exception handling.
boolisSubpath(const fs::path path, const fs::path base)<br>Checks if a path is located "downstream" from a base location.
fs::pathnormalizePath(const fs::path & originalPath)
Result< std::string, Error >readFile(const fs::path & path)
voidreportFilesystemException(const fs::filesystem_error & e)
boolweaklyEquivalent(const fs::path & path1, const fs::path & path2)<br>Compare two paths with exception handling.

Functions Documentation

function anyEquivalent

cpp
inline bool anyEquivalent(
    const fs::path & path1,
    const fs::path & path2
)
inline bool anyEquivalent(
    const fs::path & path1,
    const fs::path & path2
)

Compares two paths either using equivalent() or weaklyEquivalent().

The weak equivalence is used when either of the two paths don't exist.

function copy

cpp
inline bool copy(
    const fs::path & from,
    const fs::path & to,
    const fs::copy_options options =fs::copy_options::overwrite_existing|fs::copy_options::recursive
)
inline bool copy(
    const fs::path & from,
    const fs::path & to,
    const fs::copy_options options =fs::copy_options::overwrite_existing|fs::copy_options::recursive
)

Copy file or directory to a location.

Return: Whether the copy operation succeeded or not

The target location directory is created if necessary. Filesystem exceptions are handled and reported by this method.

function copyFile

cpp
inline bool copyFile(
    const fs::path & from,
    const fs::path & to,
    const fs::copy_options options =fs::copy_options::overwrite_existing
)
inline bool copyFile(
    const fs::path & from,
    const fs::path & to,
    const fs::copy_options options =fs::copy_options::overwrite_existing
)

Copy file to a location.

Return: Whether the copy operation succeeded or not

The target location directory is created if necessary. Filesystem exceptions are handled and reported by this method.

function copyToDir

cpp
inline bool copyToDir(
    const fs::path & from,
    const fs::path & toDir,
    const fs::copy_options options =fs::copy_options::overwrite_existing|fs::copy_options::recursive
)
inline bool copyToDir(
    const fs::path & from,
    const fs::path & toDir,
    const fs::copy_options options =fs::copy_options::overwrite_existing|fs::copy_options::recursive
)

Copy file or directory to another directory.

Return: Whether the copy operation succeeded or not

The target location directory is created if necessary. Filesystem exceptions are handled and reported by this method.

function deleteFileOrDir

cpp
inline bool deleteFileOrDir(
    const fs::path & path,
    bool deleteEmptyFolders =false
)
inline bool deleteFileOrDir(
    const fs::path & path,
    bool deleteEmptyFolders =false
)

Remove the specified file or directories.

Parameters:

  • path The file or directory to delete.
  • deleteEmptyFolders If true, any empty parent directories of the specified file or dir will be deleted as well up recursively until the root directory.

Return: Whether the delete operation succeeded.

Directories are deleted recursively.

function equivalent

cpp
inline bool equivalent(
    const fs::path & path1,
    const fs::path & path2
)
inline bool equivalent(
    const fs::path & path1,
    const fs::path & path2
)

Compare two paths with exception handling.

Calls the fs::equivalent method directly which checks if two paths are pointing to the same EXISTING file. Thus both paths MUST exist for this method to not throw an exception. Use the weaklyEquivalent() method if any of the paths don't exist.

function isSubpath

cpp
inline bool isSubpath(
    const fs::path path,
    const fs::path base
)
inline bool isSubpath(
    const fs::path path,
    const fs::path base
)

Checks if a path is located "downstream" from a base location.

This check if performed by inspecting the relative path between these two locations. The relative path must not start with going "up" a directory.

function normalizePath

cpp
inline fs::path normalizePath(
    const fs::path & originalPath
)
inline fs::path normalizePath(
    const fs::path & originalPath
)

function readFile

cpp
Result< std::string, Error > readFile(
    const fs::path & path
)
Result< std::string, Error > readFile(
    const fs::path & path
)

function reportFilesystemException

cpp
inline void reportFilesystemException(
    const fs::filesystem_error & e
)
inline void reportFilesystemException(
    const fs::filesystem_error & e
)

function weaklyEquivalent

cpp
inline bool weaklyEquivalent(
    const fs::path & path1,
    const fs::path & path2
)
inline bool weaklyEquivalent(
    const fs::path & path1,
    const fs::path & path2
)

Compare two paths with exception handling.

Uses mostly string comparison trickery. The paths do NOT have to exist.


Updated on 2024-11-06 at 20:16:53 +0000