17 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
22 #elif defined(_WIN32) || defined(_WIN64)
33 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
35 int result = stat(
string().c_str(), &status);
38 if ((errno == ENOENT) || (errno == ENOTDIR))
44 if (S_ISDIR(status.st_mode))
48 #elif defined(_WIN32) || defined(_WIN64)
62 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
63 DIR* dir = opendir(
string().c_str());
68 auto directory =
resource(dir, [](DIR* dirp) { closedir(dirp); });
70 struct dirent* pentry;
71 while ((pentry = readdir(dir)) !=
nullptr)
73 if (std::strncmp(pentry->d_name,
".",
sizeof(pentry->d_name)) == 0)
75 if (std::strncmp(pentry->d_name,
"..",
sizeof(pentry->d_name)) == 0)
81 int result = closedir(dir);
87 #elif defined(_WIN32) || defined(_WIN64)
89 HANDLE hDirectory = FindFirstFileW((*
this /
"*").
wstring().c_str(), &fd);
90 if (hDirectory == INVALID_HANDLE_VALUE)
94 auto directory =
resource(hDirectory, [](HANDLE hFindFile) { FindClose(hFindFile); });
98 if (std::wcsncmp(fd.cFileName, L
".",
countof(fd.cFileName)) == 0)
100 if (std::wcsncmp(fd.cFileName, L
"..",
countof(fd.cFileName)) == 0)
103 }
while (FindNextFileW(hDirectory, &fd) != 0);
105 if (GetLastError() != ERROR_NO_MORE_FILES)
109 if (!FindClose(hDirectory))
139 std::vector<Path> result;
140 std::regex matcher(pattern);
141 for (
auto it =
begin(); it !=
end(); ++it)
142 if (pattern.empty() || std::regex_match(it->filename().string(), matcher))
143 result.push_back(*it);
149 std::vector<Path> result;
150 std::regex matcher(pattern);
152 if (pattern.empty() || std::regex_match(it->filename().string(), matcher))
159 std::vector<Directory> result;
160 std::regex matcher(pattern);
161 for (
auto it =
begin(); it !=
end(); ++it)
170 if (pattern.empty() || std::regex_match(it->filename().string(), matcher))
171 result.emplace_back(*it);
178 std::vector<Directory> result;
179 std::regex matcher(pattern);
189 if (pattern.empty() || std::regex_match(it->filename().string(), matcher))
190 result.emplace_back(*it);
197 std::vector<File> result;
198 std::regex matcher(pattern);
199 for (
auto it =
begin(); it !=
end(); ++it)
208 if (pattern.empty() || std::regex_match(it->filename().string(), matcher))
209 result.emplace_back(*it);
216 std::vector<File> result;
217 std::regex matcher(pattern);
227 if (pattern.empty() || std::regex_match(it->filename().string(), matcher))
228 result.emplace_back(*it);
235 std::vector<Symlink> result;
236 std::regex matcher(pattern);
237 for (
auto it =
begin(); it !=
end(); ++it)
241 if (pattern.empty() || std::regex_match(it->filename().string(), matcher))
242 result.emplace_back(*it);
249 std::vector<Symlink> result;
250 std::regex matcher(pattern);
255 if (pattern.empty() || std::regex_match(it->filename().string(), matcher))
256 result.emplace_back(*it);
266 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
293 int result = mkdir(path.
string().c_str(), mode);
296 #elif defined(_WIN32) || defined(_WIN64)
297 if (!CreateDirectoryW(path.
wstring().c_str(),
nullptr))
std::vector< File > GetFilesRecursive(const std::string &pattern="")
Recursively get all files (including symbolic link files) in the current directory.
static const Flags< FileAttributes > DEFAULT_ATTRIBUTES
Default directory attributes (Normal)
std::vector< Path > GetEntriesRecursive(const std::string &pattern="")
Recursively get all entries (directories, files, symbolic links) in the current directory.
bool IsDirectoryExists() const
Is the directory exists?
DirectoryIterator begin() const
Get the directory begin iterator.
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.
DirectoryIterator end() const
Get the directory end iterator.
std::vector< Symlink > GetSymlinksRecursive(const std::string &pattern="")
Recursively get all symbolic links (including symbolic link directories) in the current directory.
static const Flags< FilePermissions > DEFAULT_PERMISSIONS
Default directory permissions (IRUSR | IWUSR | IXUSR | IRGRP | IXGRP | IROTH | IXOTH)
std::vector< Directory > GetDirectoriesRecursive(const std::string &pattern="")
Recursively get all directories (including symbolic link directories) in the current directory.
std::vector< Symlink > GetSymlinks(const std::string &pattern="")
Get all symbolic links (including symbolic link directories) in the current directory.
std::vector< Path > GetEntries(const std::string &pattern="")
Get all entries (directories, files, symbolic links) in the current directory.
DirectoryIterator rbegin() const
Get the directory recursive begin iterator.
std::vector< Directory > GetDirectories(const std::string &pattern="")
Get all directories (including symbolic link directories) in the current directory.
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.
std::vector< File > GetFiles(const std::string &pattern="")
Get all files (including symbolic link files) in the current directory.
bool IsDirectoryEmpty() const
Is the directory empty?
DirectoryIterator rend() const
Get the directory recursive end iterator.
Filesystem directory iterator.
FileSystemException & Attach(const Path &path)
Attach the given path to the exception.
std::wstring wstring() const
Get the path value as a wide string.
Flags< FileAttributes > attributes() const
Get the path file attributes.
bool IsDirectory() const
Is the path points to directory?
Path parent() const
Decompose parent path from the current path.
bool empty() const noexcept
Is the path empty?
Flags< FilePermissions > permissions() const
Get the path file permissions.
const std::string & string() const noexcept
Get the path value as UTF-8 string.
Path target() const
Read symlink target path.
Static array countof definition.
Filesystem directory definition.
#define throwex
Throw extended exception macro.
C++ Common project definitions.
auto resource(T handle, TCleaner cleaner)
Resource smart cleaner pattern.
constexpr size_t countof(const T(&)[N]) noexcept
Count of elements in static array.
@ IXOTH
Execute or search permission bit for other users.
@ IWUSR
Write permission bit for the owner of the file.
@ IWGRP
Write permission bit for the group owner of the file.
@ IXUSR
Execute (for ordinary files) or search (for directories) permission bit for the owner of the file.
@ ISVTX
This is the sticky bit.
@ IRGRP
Read permission bit for the group owner of the file.
@ IRUSR
Read permission bit for the owner of the file.
@ IXGRP
Execute or search permission bit for the group owner of the file.
@ IWOTH
Write permission bit for other users.
@ IROTH
Read permission bit for other users.
@ ISUID
This is the set-user-ID on execute bit.
@ ISGID
This is the set-group-ID on execute bit.
Resource smart cleaner pattern definition.