CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
CppCommon::Directory Class Reference

Filesystem directory. More...

#include <directory.h>

Inheritance diagram for CppCommon::Directory:
CppCommon::Path

Public Member Functions

 Directory ()
 Initialize directory with an empty path. More...
 
 Directory (const Path &path)
 Initialize directory with a given path. More...
 
 Directory (const Directory &)=default
 
 Directory (Directory &&)=default
 
 ~Directory ()=default
 
Directoryoperator= (const Path &path)
 
Directoryoperator= (const Directory &)=default
 
Directoryoperator= (Directory &&)=default
 
 operator bool () const noexcept
 Check if the directory exist. More...
 
bool IsDirectoryExists () const
 Is the directory exists? More...
 
bool IsDirectoryEmpty () const
 Is the directory empty? More...
 
DirectoryIterator begin () const
 Get the directory begin iterator. More...
 
DirectoryIterator end () const
 Get the directory end iterator. More...
 
DirectoryIterator rbegin () const
 Get the directory recursive begin iterator. More...
 
DirectoryIterator rend () const
 Get the directory recursive end iterator. More...
 
std::vector< PathGetEntries (const std::string &pattern="")
 Get all entries (directories, files, symbolic links) in the current directory. More...
 
std::vector< PathGetEntriesRecursive (const std::string &pattern="")
 Recursively get all entries (directories, files, symbolic links) in the current directory. More...
 
std::vector< DirectoryGetDirectories (const std::string &pattern="")
 Get all directories (including symbolic link directories) in the current directory. More...
 
std::vector< DirectoryGetDirectoriesRecursive (const std::string &pattern="")
 Recursively get all directories (including symbolic link directories) in the current directory. More...
 
std::vector< FileGetFiles (const std::string &pattern="")
 Get all files (including symbolic link files) in the current directory. More...
 
std::vector< FileGetFilesRecursive (const std::string &pattern="")
 Recursively get all files (including symbolic link files) in the current directory. More...
 
std::vector< SymlinkGetSymlinks (const std::string &pattern="")
 Get all symbolic links (including symbolic link directories) in the current directory. More...
 
std::vector< SymlinkGetSymlinksRecursive (const std::string &pattern="")
 Recursively get all symbolic links (including symbolic link directories) in the current directory. More...
 
void swap (Directory &directory) noexcept
 Swap two instances. More...
 
- Public Member Functions inherited from CppCommon::Path
 Path ()
 Initialize path with an empty value. More...
 
 Path (const char *path)
 Initialize path with a given C-string value. More...
 
 Path (const std::string &path)
 Initialize path with a given string value. More...
 
 Path (const wchar_t *path)
 Initialize path with a given wide C-string value. More...
 
 Path (const std::wstring &path)
 Initialize path with a given wide string value. More...
 
 Path (const Path &)=default
 
 Path (Path &&)=default
 
 ~Path ()=default
 
Pathoperator= (const Path &)=default
 
Pathoperator= (Path &&)=default
 
 operator bool () const noexcept
 Check if the path is not empty. More...
 
Pathoperator/= (const Path &path)
 
Pathoperator+= (const Path &path)
 
const std::string & string () const noexcept
 Get the path value as UTF-8 string. More...
 
std::wstring wstring () const
 Get the path value as a wide string. More...
 
Path root () const
 Decompose root path from the current path. More...
 
Path relative () const
 Decompose relative path from the current path. More...
 
Path parent () const
 Decompose parent path from the current path. More...
 
Path filename () const
 Decompose filename from the current path. More...
 
Path stem () const
 Decompose stem from the current path. More...
 
Path extension () const
 Decompose extension from the current path. More...
 
Path absolute () const
 Transform the current path to the real path on a filesystem. More...
 
Path canonical () const
 Transform the current path and replace all '.' and '..' properly. More...
 
Path validate (char placeholder='_') const
 Transform the current path and replace all deprecated characters with a given placeholder (default is '_') More...
 
FileType type () const
 Get the path file type. More...
 
Flags< FileAttributesattributes () const
 Get the path file attributes. More...
 
Flags< FilePermissionspermissions () const
 Get the path file permissions. More...
 
UtcTimestamp created () const
 Get the path created UTC timestamp. More...
 
UtcTimestamp modified () const
 Get the path modified UTC timestamp. More...
 
size_t hardlinks () const
 Get the path count of hardlinks. More...
 
SpaceInfo space () const
 Get the path space information. More...
 
bool empty () const noexcept
 Is the path empty? More...
 
bool HasRoot () const
 Has root path? More...
 
bool HasRelative () const
 Has relative path? More...
 
bool HasParent () const
 Has parent path? More...
 
bool HasFilename () const
 Has filename? More...
 
bool HasStem () const
 Has stem? More...
 
bool HasExtension () const
 Has extension? More...
 
bool IsAbsolute () const
 Is absolute path? More...
 
bool IsRelative () const
 Is relative path? More...
 
bool IsExists () const
 Is the path exists? More...
 
bool IsRegularFile () const
 Is the path points to regular file? More...
 
bool IsDirectory () const
 Is the path points to directory? More...
 
bool IsSymlink () const
 Is the path points to symbolic link? More...
 
bool IsOther () const
 Is the path points to special file (block, character, FIFO, socket)? More...
 
bool IsEquivalent (const Path &path) const
 Is the current path is equivalent to the given one (points to the same node on a filesystem)? More...
 
void Clear () noexcept
 Clear the path content. More...
 
PathAssign (const Path &path)
 Assign the given path to the current one. More...
 
PathAppend (const Path &path)
 Append the given path to the current one. More...
 
PathConcat (const Path &path)
 Concatenate the given path to the current one. More...
 
PathMakePreferred ()
 Convert all path separators to system ones ('\' for Windows or '/' for Unix) More...
 
PathReplaceFilename (const Path &filename)
 Replace the current path filename with a given one. More...
 
PathReplaceExtension (const Path &extension)
 Replace the current path extension with a given one. More...
 
PathRemoveFilename ()
 Remove the current path filename. More...
 
PathRemoveExtension ()
 Remove the current path extension. More...
 
PathRemoveTrailingSeparators ()
 Remove all trailing separators form the current path. More...
 
void swap (Path &path) noexcept
 Swap two instances. More...
 

Static Public Member Functions

static Directory Create (const Path &path, const Flags< FileAttributes > &attributes=Directory::DEFAULT_ATTRIBUTES, const Flags< FilePermissions > &permissions=Directory::DEFAULT_PERMISSIONS)
 Create directory from the given path. More...
 
static Directory CreateTree (const Path &path, const Flags< FileAttributes > &attributes=Directory::DEFAULT_ATTRIBUTES, const Flags< FilePermissions > &permissions=Directory::DEFAULT_PERMISSIONS)
 Create full directory tree of the given path. More...
 
- Static Public Member Functions inherited from CppCommon::Path
static bool deprecated (char character) noexcept
 Is the given character is deprecated by the filesystem? More...
 
static bool deprecated (wchar_t character) noexcept
 Is the given wide character is deprecated by the filesystem? More...
 
static std::string deprecated ()
 Get filesystem deprecated characters ('\', '/', '?', '', '*', ':', '|', '"', '<', '>') More...
 
static char separator () noexcept
 Get the system path separator character ('\' for Windows or '/' for Unix) More...
 
static Path initial ()
 Get the initial path of the process. More...
 
static Path current ()
 Get the current path of the process. More...
 
static Path executable ()
 Get the executable path of the process. More...
 
static Path home ()
 Get the home path of the process. More...
 
static Path temp ()
 Get the temporary path of the process. More...
 
static Path unique ()
 Get the unique filename in UUID format "00000000-0000-0000-0000-000000000000". More...
 
static Path Copy (const Path &src, const Path &dst, bool overwrite=false)
 Copy the given source path to destination path (file, empty directory, symlink, etc) More...
 
static Path CopyIf (const Path &src, const Path &dst, const std::string &pattern="", bool overwrite=false)
 Copy all matched files from the the given source path to destination path (files, directories, symlinks, etc) More...
 
static Path CopyAll (const Path &src, const Path &dst, bool overwrite=false)
 Recursively copy the given source path to destination path (files, directories, symlinks, etc) More...
 
static Path Rename (const Path &src, const Path &dst)
 Rename the given source path to destination path (file, empty directory, symlink, etc) More...
 
static Path Remove (const Path &path)
 Remove the given path (file, empty directory, symlink, etc) from the filesystem. More...
 
static Path RemoveAll (const Path &path)
 Recursively remove the given path (file, empty directory, symlink, etc) from the filesystem. More...
 
static Path RemoveIf (const Path &path, const std::string &pattern="")
 Recursively remove the given path matched to the given pattern (file, empty directory, symlink, etc) from the filesystem. More...
 
static void SetAttributes (const Path &path, const Flags< FileAttributes > &attributes)
 Set file attributes for the given path. More...
 
static void SetPermissions (const Path &path, const Flags< FilePermissions > &permissions)
 Set file permissions for the given path. More...
 
static void SetCreated (const Path &path, const UtcTimestamp &timestamp)
 Set created UTC timestamp for the given path. More...
 
static void SetModified (const Path &path, const UtcTimestamp &timestamp)
 Set modified UTC timestamp for the given path. More...
 
static void SetCurrent (const Path &path)
 Set the given path of the process as a current one. More...
 
static void Touch (const Path &path)
 Touch the given path and set its modified UTC timestamp to the current value. More...
 

Static Public Attributes

static const Flags< FileAttributesDEFAULT_ATTRIBUTES = FileAttributes::NORMAL
 Default directory attributes (Normal) More...
 
static const Flags< FilePermissionsDEFAULT_PERMISSIONS = FilePermissions::IRUSR | FilePermissions::IWUSR | FilePermissions::IXUSR | FilePermissions::IRGRP | FilePermissions::IXGRP | FilePermissions::IROTH | FilePermissions::IXOTH
 Default directory permissions (IRUSR | IWUSR | IXUSR | IRGRP | IXGRP | IROTH | IXOTH) More...
 

Friends

void swap (Directory &directory1, Directory &directory2) noexcept
 

Additional Inherited Members

- Protected Attributes inherited from CppCommon::Path
std::string _path
 Path string. More...
 

Detailed Description

Filesystem directory.

Filesystem directory wraps directory management operations (create, remove, iterate).

Not thread-safe.

Examples
filesystem_directory.cpp.

Definition at line 24 of file directory.h.

Constructor & Destructor Documentation

◆ Directory() [1/4]

CppCommon::Directory::Directory ( )
inline

Initialize directory with an empty path.

Definition at line 33 of file directory.h.

◆ Directory() [2/4]

CppCommon::Directory::Directory ( const Path path)
inline

Initialize directory with a given path.

Parameters
path- Directory path

Definition at line 38 of file directory.h.

◆ Directory() [3/4]

CppCommon::Directory::Directory ( const Directory )
default

◆ Directory() [4/4]

CppCommon::Directory::Directory ( Directory &&  )
default

◆ ~Directory()

CppCommon::Directory::~Directory ( )
default

Member Function Documentation

◆ begin()

DirectoryIterator CppCommon::Directory::begin ( ) const

Get the directory begin iterator.

Definition at line 117 of file directory.cpp.

◆ Create()

Directory CppCommon::Directory::Create ( const Path path,
const Flags< FileAttributes > &  attributes = Directory::DEFAULT_ATTRIBUTES,
const Flags< FilePermissions > &  permissions = Directory::DEFAULT_PERMISSIONS 
)
static

Create directory from the given path.

Parameters
path- Directory path
attributes- Directory attributes (default is Directory::DEFAULT_ATTRIBUTES)
permissions- Directory permissions (default is Directory::DEFAULT_PERMISSIONS)
Returns
Created directory

Definition at line 261 of file directory.cpp.

◆ CreateTree()

Directory CppCommon::Directory::CreateTree ( const Path path,
const Flags< FileAttributes > &  attributes = Directory::DEFAULT_ATTRIBUTES,
const Flags< FilePermissions > &  permissions = Directory::DEFAULT_PERMISSIONS 
)
static

Create full directory tree of the given path.

Parameters
path- Directory path
attributes- Directory attributes (default is Directory::DEFAULT_ATTRIBUTES)
permissions- Directory permissions (default is Directory::DEFAULT_PERMISSIONS)
Returns
Created full directory tree

Definition at line 303 of file directory.cpp.

◆ end()

DirectoryIterator CppCommon::Directory::end ( ) const

Get the directory end iterator.

Definition at line 122 of file directory.cpp.

◆ GetDirectories()

std::vector< Directory > CppCommon::Directory::GetDirectories ( const std::string &  pattern = "")

Get all directories (including symbolic link directories) in the current directory.

Parameters
pattern- Regular expression pattern (default is "")
Returns
Directories collection

Definition at line 157 of file directory.cpp.

◆ GetDirectoriesRecursive()

std::vector< Directory > CppCommon::Directory::GetDirectoriesRecursive ( const std::string &  pattern = "")

Recursively get all directories (including symbolic link directories) in the current directory.

Parameters
pattern- Regular expression pattern (default is "")
Returns
Directories collection

Definition at line 176 of file directory.cpp.

◆ GetEntries()

std::vector< Path > CppCommon::Directory::GetEntries ( const std::string &  pattern = "")

Get all entries (directories, files, symbolic links) in the current directory.

Parameters
pattern- Regular expression pattern (default is "")
Returns
Entries collection

Definition at line 137 of file directory.cpp.

◆ GetEntriesRecursive()

std::vector< Path > CppCommon::Directory::GetEntriesRecursive ( const std::string &  pattern = "")

Recursively get all entries (directories, files, symbolic links) in the current directory.

Parameters
pattern- Regular expression pattern (default is "")
Returns
Entries collection

Definition at line 147 of file directory.cpp.

◆ GetFiles()

std::vector< File > CppCommon::Directory::GetFiles ( const std::string &  pattern = "")

Get all files (including symbolic link files) in the current directory.

Parameters
pattern- Regular expression pattern (default is "")
Returns
Files collection

Definition at line 195 of file directory.cpp.

◆ GetFilesRecursive()

std::vector< File > CppCommon::Directory::GetFilesRecursive ( const std::string &  pattern = "")

Recursively get all files (including symbolic link files) in the current directory.

Parameters
pattern- Regular expression pattern (default is "")
Returns
Files collection

Definition at line 214 of file directory.cpp.

◆ GetSymlinks()

std::vector< Symlink > CppCommon::Directory::GetSymlinks ( const std::string &  pattern = "")

Get all symbolic links (including symbolic link directories) in the current directory.

Parameters
pattern- Regular expression pattern (default is "")
Returns
Symbolic links collection

Definition at line 233 of file directory.cpp.

◆ GetSymlinksRecursive()

std::vector< Symlink > CppCommon::Directory::GetSymlinksRecursive ( const std::string &  pattern = "")

Recursively get all symbolic links (including symbolic link directories) in the current directory.

Parameters
pattern- Regular expression pattern (default is "")
Returns
Symbolic links collection

Definition at line 247 of file directory.cpp.

◆ IsDirectoryEmpty()

bool CppCommon::Directory::IsDirectoryEmpty ( ) const

Is the directory empty?

Definition at line 60 of file directory.cpp.

◆ IsDirectoryExists()

bool CppCommon::Directory::IsDirectoryExists ( ) const

Is the directory exists?

Definition at line 31 of file directory.cpp.

◆ operator bool()

CppCommon::Directory::operator bool ( ) const
inlineexplicitnoexcept

Check if the directory exist.

Definition at line 49 of file directory.h.

◆ operator=() [1/3]

Directory& CppCommon::Directory::operator= ( const Directory )
default

◆ operator=() [2/3]

Directory& CppCommon::Directory::operator= ( const Path path)
inline

Definition at line 43 of file directory.h.

◆ operator=() [3/3]

Directory& CppCommon::Directory::operator= ( Directory &&  )
default

◆ rbegin()

DirectoryIterator CppCommon::Directory::rbegin ( ) const

Get the directory recursive begin iterator.

Definition at line 127 of file directory.cpp.

◆ rend()

DirectoryIterator CppCommon::Directory::rend ( ) const

Get the directory recursive end iterator.

Definition at line 132 of file directory.cpp.

◆ swap()

void CppCommon::Directory::swap ( Directory directory)
inlinenoexcept

Swap two instances.

Definition at line 11 of file directory.inl.

Friends And Related Function Documentation

◆ swap

void swap ( Directory directory1,
Directory directory2 
)
friend

Definition at line 17 of file directory.inl.

Member Data Documentation

◆ DEFAULT_ATTRIBUTES

const Flags< FileAttributes > CppCommon::Directory::DEFAULT_ATTRIBUTES = FileAttributes::NORMAL
static

Default directory attributes (Normal)

Definition at line 28 of file directory.h.

◆ DEFAULT_PERMISSIONS

Default directory permissions (IRUSR | IWUSR | IXUSR | IRGRP | IXGRP | IROTH | IXOTH)

Definition at line 30 of file directory.h.


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