SPH
|
Classes | |
class | ScopedWorkingDirectory |
class | DirectoryIterator |
Iterator allowing to enumerate files and subdirectories in given directory. More... | |
class | DirectoryAdapter |
Object providing begin and end directory iterator for given directory path. More... | |
class | FileLock |
Locks a file. More... | |
Enumerations | |
enum class | PathType { FILE , DIRECTORY , SYMLINK , OTHER } |
enum class | CreateDirectoryFlag { ALLOW_EXISTING = 1 << 0 } |
enum class | RemovePathFlag { RECURSIVE = 1 << 1 } |
Functions | |
std::string | readFile (const Path &path) |
Reads the whole file into the string. More... | |
bool | pathExists (const Path &path) |
Checks if a file or directory exists (or more precisely, if a file or directory is accessible). More... | |
Size | fileSize (const Path &path) |
Returns the size of a file. More... | |
bool | isPathWritable (const Path &path) |
Checks whether the given file is writable. More... | |
Expected< Path > | getHomeDirectory () |
Returns the home directory of the current user. More... | |
Path | getAbsolutePath (const Path &relativePath) |
Returns the absolute path to the file. More... | |
Expected< PathType > | pathType (const Path &path) |
Returns the type of the given path, or error message if the function fails. More... | |
Outcome | createDirectory (const Path &path, const Flags< CreateDirectoryFlag > flags=CreateDirectoryFlag::ALLOW_EXISTING) |
Creates a directory with given path. Creates all parent directories as well. More... | |
Outcome | removePath (const Path &path, const Flags< RemovePathFlag > flags=EMPTY_FLAGS) |
Outcome | copyFile (const Path &from, const Path &to) |
Copies a file on given path to a different path. More... | |
Outcome | copyDirectory (const Path &from, const Path &to) |
Copies a directory (and all files and subdirectories it contains) to a different path. More... | |
void | setWorkingDirectory (const Path &path) |
Changes the current working directory. More... | |
DirectoryAdapter | iterateDirectory (const Path &directory) |
Array< Path > | getFilesInDirectory (const Path &directory) |
Alternatitve to iterateDirectory, returning all files in directory in an array. More... | |
bool | isFileLocked (const Path &path) |
|
strong |
Enumerator | |
---|---|
ALLOW_EXISTING | If the named directory already exists, function returns SUCCESS instead of error message. |
Definition at line 50 of file FileSystem.h.
|
strong |
Enumerator | |
---|---|
FILE | Regular file. |
DIRECTORY | Directory. |
SYMLINK | Symbolic link. |
OTHER | Pipe, socket, ... |
Definition at line 39 of file FileSystem.h.
|
strong |
Enumerator | |
---|---|
RECURSIVE | Removes also all subdirectories. If not used, removing non-empty directory will return an error. Option has no effect for files. |
Definition at line 64 of file FileSystem.h.
Copies a directory (and all files and subdirectories it contains) to a different path.
The original directory is not changed. If there is already a directory on target path, it is overriden. All parent directories of target path are created, if necessary.
Definition at line 247 of file FileSystem.cpp.
Copies a file on given path to a different path.
The original file is not changed. If there is already a file on target path, the file is overriden. All parent directories of target path are created, if necessary.
from | Source file to be copied. |
to | Target path where the copy is saved. |
Definition at line 219 of file FileSystem.cpp.
Outcome FileSystem::createDirectory | ( | const Path & | path, |
const Flags< CreateDirectoryFlag > | flags = CreateDirectoryFlag::ALLOW_EXISTING |
||
) |
Creates a directory with given path. Creates all parent directories as well.
If empty path is passed, the function returns SUCCESS without actually doing anything, it is therefore possible to use constructs like
even with relative paths.
Definition at line 119 of file FileSystem.cpp.
Returns the size of a file.
The file must exist and be accessible, checked by assert.
Definition at line 29 of file FileSystem.cpp.
Returns the absolute path to the file.
Function also resolves all symlinks in the path.
Definition at line 48 of file FileSystem.cpp.
Alternatitve to iterateDirectory, returning all files in directory in an array.
Returns relative paths with respect to the given parent directory.
Definition at line 342 of file FileSystem.cpp.
Returns the home directory of the current user.
Definition at line 39 of file FileSystem.cpp.
bool FileSystem::isFileLocked | ( | const Path & | path | ) |
bool FileSystem::isPathWritable | ( | const Path & | path | ) |
Checks whether the given file is writable.
Definition at line 35 of file FileSystem.cpp.
FileSystem::DirectoryAdapter FileSystem::iterateDirectory | ( | const Path & | directory | ) |
Syntactic suggar, function simply returning the DirectoryAdapter for given path.
Usage:
Definition at line 338 of file FileSystem.cpp.
bool FileSystem::pathExists | ( | const Path & | path | ) |
Checks if a file or directory exists (or more precisely, if a file or directory is accessible).
Definition at line 21 of file FileSystem.cpp.
Expected< FileSystem::PathType > FileSystem::pathType | ( | const Path & | path | ) |
Returns the type of the given path, or error message if the function fails.
Definition at line 54 of file FileSystem.cpp.
NAMESPACE_SPH_BEGIN std::string FileSystem::readFile | ( | const Path & | path | ) |
Reads the whole file into the string.
Returns an empty string if the file does not exist or cannot be opened for reading.
path | File to read |
Definition at line 14 of file FileSystem.cpp.
Outcome FileSystem::removePath | ( | const Path & | path, |
const Flags< RemovePathFlag > | flags = EMPTY_FLAGS |
||
) |
Removes a file or a directory at given path.
path | Path to a file or directory to remove. |
flags | Optional parameters of the function, see RemovePathFlag enum. |
Definition at line 137 of file FileSystem.cpp.
void FileSystem::setWorkingDirectory | ( | const Path & | path | ) |
Changes the current working directory.
Definition at line 273 of file FileSystem.cpp.