olp-cpp-sdk  1.22.0
Public Types | Static Public Member Functions | List of all members
olp::utils::Dir Class Reference

Manages directories. More...

#include <Dir.h>

Public Types

using FilterFunction = std::function< bool(const std::string &)>
 An alias for the filter function.
 
using PathCallback = std::function< void(const std::string &)>
 An alias for the path callback function.
 

Static Public Member Functions

static bool Exists (const std::string &path)
 Checks whether a directory exists. More...
 
static bool Remove (const std::string &path)
 Removes a directory and deletes all its subfolders and files. More...
 
static bool Create (const std::string &path, bool extend_permissions=false)
 Creates a directory and all required directories specified in the path. More...
 
static std::string TempDirectory ()
 Gets a platform-specific temporary path. More...
 
static bool FileExists (const std::string &file_path)
 Checks whether the provided file exists. More...
 
static uint64_t Size (const std::string &path, FilterFunction filter_fn={})
 Calculates the size of a directory. More...
 
static bool IsReadOnly (const std::string &path)
 Checks if the current application and user has a read only access to given path. More...
 
static void ForEachDirectory (const std::string &path, PathCallback path_fn)
 Iterates through top-level directories in the provided path and calls the provided callback function for each directory. More...
 

Detailed Description

Manages directories.

Member Function Documentation

◆ Create()

static bool olp::utils::Dir::Create ( const std::string &  path,
bool  extend_permissions = false 
)
static

Creates a directory and all required directories specified in the path.

Parameters
pathThe path of the directory.
extend_permissionsControls the permission extension.

Note: extend_permissions are applicable for Unix systems, if enabled, it sets the 0777 permissions for created folders.

Returns
True if the operation is successful; false otherwise.

◆ Exists()

static bool olp::utils::Dir::Exists ( const std::string &  path)
static

Checks whether a directory exists.

Parameters
pathThe path of the directory.
Returns
True if the directory exists; false otherwise.

◆ FileExists()

static bool olp::utils::Dir::FileExists ( const std::string &  file_path)
static

Checks whether the provided file exists.

Parameters
file_pathThe path of the file.
Returns
True if the file with the given path exists; false otherwise.

◆ ForEachDirectory()

static void olp::utils::Dir::ForEachDirectory ( const std::string &  path,
PathCallback  path_fn 
)
static

Iterates through top-level directories in the provided path and calls the provided callback function for each directory.

Parameters
pathThe path of the root directory.
path_fnThe callback function with a relative path.

◆ IsReadOnly()

static bool olp::utils::Dir::IsReadOnly ( const std::string &  path)
static

Checks if the current application and user has a read only access to given path.

Parameters
pathThe path to check for read only access.
Returns
True if current application and user has read only access to the path.

◆ Remove()

static bool olp::utils::Dir::Remove ( const std::string &  path)
static

Removes a directory and deletes all its subfolders and files.

Parameters
pathThe path of the directory.
Returns
True if the operation is successful; false otherwise.

◆ Size()

static uint64_t olp::utils::Dir::Size ( const std::string &  path,
FilterFunction  filter_fn = {} 
)
static

Calculates the size of a directory.

Use a filter to exclude unnecessary files or directories from the calculation.

Note
This method will go all the way recursive for as long as needed to gather all files which pass the given filter.
Parameters
pathThe path of the directory.
filter_fnThe filter function.
Returns
The calculated size.

◆ TempDirectory()

static std::string olp::utils::Dir::TempDirectory ( )
static

Gets a platform-specific temporary path.

Returns
The platform-specific temporary path of the directory.

The documentation for this class was generated from the following file: