Devel Lib
Devel::IO::CDir Class Reference

A class for directory operations. More...

#include <Dir.h>

Public Member Functions

 CDir ()=default
 Default constructor for CDir.
 
 CDir (CPath i_oPath)
 Construct a CDir object using the provided path. More...
 
std::vector< CPathgetDirectoryFiles (bool i_bIsRecursive=false, std::optional< std::vector< std::string >> i_astExtensionFilters=std::nullopt)
 Get the files in the directory. More...
 

Static Public Member Functions

static bool createDirectories (const CPath &i_oPath)
 Static function to create directories. More...
 
static void createDirectorySymlink (const CPath &i_oTargetPath, const CPath &i_oLinkPath)
 Static function to create a symlink for a directory. More...
 
static bool isDirectory (const CPath &i_oPath)
 Static function to check if a path is a directory. More...
 
static CPath getTempDirectoryPath ()
 Static function to get the path of the temporary directory. More...
 

Detailed Description

A class for directory operations.

This class encapsulates operations related to directories like getting directory files, creating directories, creating directory symlink, and more.

Example

The following example demonstrates how to use various functionalities of the CDir class.

// Creating an instance of CDir for a specific path
Devel::IO::CDir dir = Devel::IO::CDir::CDir(CPath("/path/to/directory"));
// Get all files in the directory (not recursively)
std::vector<CPath> files = dir.getDirectoryFiles();
// Get all ".txt" files in the directory and its subdirectories
std::vector<CPath> txtFiles = dir.getDirectoryFiles(true, std::vector<std::string>{".txt"});
// Create a new directory
bool success = Devel::IO::CDir::createDirectories(CPath("/path/to/new/directory"));
// Create a symlink for a directory
Devel::IO::CDir::createDirectorySymlink(CPath("/path/to/original/directory"), CPath("/path/to/symlink"));
// Check if a path is a directory
bool isDir = Devel::IO::CDir::isDirectory(CPath("/path/to/check"));
// Get the path of the temporary directory
A class for directory operations.
Definition: Dir.h:46
static CPath getTempDirectoryPath()
Static function to get the path of the temporary directory.
Definition: Dir.h:90
static bool createDirectories(const CPath &i_oPath)
Static function to create directories.
Definition: Dir.h:70
std::vector< CPath > getDirectoryFiles(bool i_bIsRecursive=false, std::optional< std::vector< std::string >> i_astExtensionFilters=std::nullopt)
Get the files in the directory.
Definition: Dir.cpp:29
static bool isDirectory(const CPath &i_oPath)
Static function to check if a path is a directory.
Definition: Dir.h:84
CDir()=default
Default constructor for CDir.
static void createDirectorySymlink(const CPath &i_oTargetPath, const CPath &i_oLinkPath)
Static function to create a symlink for a directory.
Definition: Dir.h:77

Constructor & Destructor Documentation

◆ CDir()

Devel::IO::CDir::CDir ( CPath  i_oPath)
inlineexplicit

Construct a CDir object using the provided path.

Parameters
i_oPath- The path for the directory.

Member Function Documentation

◆ createDirectories()

static bool Devel::IO::CDir::createDirectories ( const CPath i_oPath)
inlinestatic

Static function to create directories.

Parameters
i_oPath- The path where the directories should be created.
Returns
true if the directories were successfully created, false otherwise.

◆ createDirectorySymlink()

static void Devel::IO::CDir::createDirectorySymlink ( const CPath i_oTargetPath,
const CPath i_oLinkPath 
)
inlinestatic

Static function to create a symlink for a directory.

Parameters
i_oTargetPath- The original directory.
i_oLinkPath- The symlink path.

◆ getDirectoryFiles()

std::vector< Devel::IO::CPath > Devel::IO::CDir::getDirectoryFiles ( bool  i_bIsRecursive = false,
std::optional< std::vector< std::string >>  i_astExtensionFilters = std::nullopt 
)

Get the files in the directory.

Parameters
i_bIsRecursive- Whether to recursively look in subdirectories.
i_astExtensionFilters- Optional list of file extensions to filter.
Returns
A vector containing the paths of the files.

◆ getTempDirectoryPath()

static CPath Devel::IO::CDir::getTempDirectoryPath ( )
inlinestatic

Static function to get the path of the temporary directory.

Returns
The path of the temporary directory.

◆ isDirectory()

static bool Devel::IO::CDir::isDirectory ( const CPath i_oPath)
inlinestatic

Static function to check if a path is a directory.

Parameters
i_oPath- The path to check.
Returns
true if the path is a directory, false otherwise.

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