CppCommon
1.0.4.1
C++ Common Library
|
Filesystem directory. More...
#include <directory.h>
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 | |
Directory & | operator= (const Path &path) |
Directory & | operator= (const Directory &)=default |
Directory & | operator= (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< Path > | GetEntries (const std::string &pattern="") |
Get all entries (directories, files, symbolic links) in the current directory. More... | |
std::vector< Path > | GetEntriesRecursive (const std::string &pattern="") |
Recursively get all entries (directories, files, symbolic links) in the current directory. More... | |
std::vector< Directory > | GetDirectories (const std::string &pattern="") |
Get all directories (including symbolic link directories) in the current directory. More... | |
std::vector< Directory > | GetDirectoriesRecursive (const std::string &pattern="") |
Recursively get all directories (including symbolic link directories) in the current directory. More... | |
std::vector< File > | GetFiles (const std::string &pattern="") |
Get all files (including symbolic link files) in the current directory. More... | |
std::vector< File > | GetFilesRecursive (const std::string &pattern="") |
Recursively get all files (including symbolic link files) in the current directory. More... | |
std::vector< Symlink > | GetSymlinks (const std::string &pattern="") |
Get all symbolic links (including symbolic link directories) in the current directory. More... | |
std::vector< Symlink > | GetSymlinksRecursive (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 | |
Path & | operator= (const Path &)=default |
Path & | operator= (Path &&)=default |
operator bool () const noexcept | |
Check if the path is not empty. More... | |
Path & | operator/= (const Path &path) |
Path & | operator+= (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< FileAttributes > | attributes () const |
Get the path file attributes. More... | |
Flags< FilePermissions > | permissions () 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... | |
Path & | Assign (const Path &path) |
Assign the given path to the current one. More... | |
Path & | Append (const Path &path) |
Append the given path to the current one. More... | |
Path & | Concat (const Path &path) |
Concatenate the given path to the current one. More... | |
Path & | MakePreferred () |
Convert all path separators to system ones ('\' for Windows or '/' for Unix) More... | |
Path & | ReplaceFilename (const Path &filename) |
Replace the current path filename with a given one. More... | |
Path & | ReplaceExtension (const Path &extension) |
Replace the current path extension with a given one. More... | |
Path & | RemoveFilename () |
Remove the current path filename. More... | |
Path & | RemoveExtension () |
Remove the current path extension. More... | |
Path & | RemoveTrailingSeparators () |
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 ×tamp) |
Set created UTC timestamp for the given path. More... | |
static void | SetModified (const Path &path, const UtcTimestamp ×tamp) |
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< FileAttributes > | DEFAULT_ATTRIBUTES = FileAttributes::NORMAL |
Default directory attributes (Normal) More... | |
static const Flags< FilePermissions > | DEFAULT_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... | |
Filesystem directory.
Filesystem directory wraps directory management operations (create, remove, iterate).
Not thread-safe.
Definition at line 24 of file directory.h.
|
inline |
Initialize directory with an empty path.
Definition at line 33 of file directory.h.
|
inline |
Initialize directory with a given path.
path | - Directory path |
Definition at line 38 of file directory.h.
|
default |
|
default |
|
default |
DirectoryIterator CppCommon::Directory::begin | ( | ) | const |
Get the directory begin iterator.
Definition at line 117 of file directory.cpp.
|
static |
Create directory from the given path.
path | - Directory path |
attributes | - Directory attributes (default is Directory::DEFAULT_ATTRIBUTES) |
permissions | - Directory permissions (default is Directory::DEFAULT_PERMISSIONS) |
Definition at line 261 of file directory.cpp.
|
static |
Create full directory tree of the given path.
path | - Directory path |
attributes | - Directory attributes (default is Directory::DEFAULT_ATTRIBUTES) |
permissions | - Directory permissions (default is Directory::DEFAULT_PERMISSIONS) |
Definition at line 303 of file directory.cpp.
DirectoryIterator CppCommon::Directory::end | ( | ) | const |
Get the directory end iterator.
Definition at line 122 of file directory.cpp.
std::vector< Directory > CppCommon::Directory::GetDirectories | ( | const std::string & | pattern = "" | ) |
Get all directories (including symbolic link directories) in the current directory.
pattern | - Regular expression pattern (default is "") |
Definition at line 157 of file directory.cpp.
std::vector< Directory > CppCommon::Directory::GetDirectoriesRecursive | ( | const std::string & | pattern = "" | ) |
Recursively get all directories (including symbolic link directories) in the current directory.
pattern | - Regular expression pattern (default is "") |
Definition at line 176 of file directory.cpp.
std::vector< Path > CppCommon::Directory::GetEntries | ( | const std::string & | pattern = "" | ) |
Get all entries (directories, files, symbolic links) in the current directory.
pattern | - Regular expression pattern (default is "") |
Definition at line 137 of file directory.cpp.
std::vector< Path > CppCommon::Directory::GetEntriesRecursive | ( | const std::string & | pattern = "" | ) |
Recursively get all entries (directories, files, symbolic links) in the current directory.
pattern | - Regular expression pattern (default is "") |
Definition at line 147 of file directory.cpp.
std::vector< File > CppCommon::Directory::GetFiles | ( | const std::string & | pattern = "" | ) |
Get all files (including symbolic link files) in the current directory.
pattern | - Regular expression pattern (default is "") |
Definition at line 195 of file directory.cpp.
std::vector< File > CppCommon::Directory::GetFilesRecursive | ( | const std::string & | pattern = "" | ) |
Recursively get all files (including symbolic link files) in the current directory.
pattern | - Regular expression pattern (default is "") |
Definition at line 214 of file directory.cpp.
std::vector< Symlink > CppCommon::Directory::GetSymlinks | ( | const std::string & | pattern = "" | ) |
Get all symbolic links (including symbolic link directories) in the current directory.
pattern | - Regular expression pattern (default is "") |
Definition at line 233 of file directory.cpp.
std::vector< Symlink > CppCommon::Directory::GetSymlinksRecursive | ( | const std::string & | pattern = "" | ) |
Recursively get all symbolic links (including symbolic link directories) in the current directory.
pattern | - Regular expression pattern (default is "") |
Definition at line 247 of file directory.cpp.
bool CppCommon::Directory::IsDirectoryEmpty | ( | ) | const |
Is the directory empty?
Definition at line 60 of file directory.cpp.
bool CppCommon::Directory::IsDirectoryExists | ( | ) | const |
Is the directory exists?
Definition at line 31 of file directory.cpp.
|
inlineexplicitnoexcept |
Check if the directory exist.
Definition at line 49 of file directory.h.
Definition at line 43 of file directory.h.
DirectoryIterator CppCommon::Directory::rbegin | ( | ) | const |
Get the directory recursive begin iterator.
Definition at line 127 of file directory.cpp.
DirectoryIterator CppCommon::Directory::rend | ( | ) | const |
Get the directory recursive end iterator.
Definition at line 132 of file directory.cpp.
|
inlinenoexcept |
Swap two instances.
Definition at line 11 of file directory.inl.
Definition at line 17 of file directory.inl.
|
static |
Default directory attributes (Normal)
Definition at line 28 of file directory.h.
|
static |
Default directory permissions (IRUSR | IWUSR | IXUSR | IRGRP | IXGRP | IROTH | IXOTH)
Definition at line 30 of file directory.h.