Execute fs operations { exists, copy, delete } for { files and directories }. More...
#include <FileSystem.h>
Classes | |
| struct | CopyOperation |
| Specify source, destination and flags for a copy operation. More... | |
| struct | Operations |
| Low level filesystem API, requiring paths in native encoding (UTF-16 on Windows, UTF-8 elsewhere) More... | |
Public Types | |
| using | AccessMode = FileSystemAccessMode |
| Access mode for path checks. | |
| using | CopyFlags = FileSystemCopyFlags |
| Specify copy options like overwriting existing files. | |
| using | FileStat = FileSystemStat |
| A structure to describe modified time. | |
Public Member Functions | |
| Result | init (StringSpan initialDirectory) |
| Call init function when instantiating the class to set directory for all operations using relative paths. | |
| Result | changeDirectory (StringSpan newDirectory) |
| Changes current directory. | |
| Result | copyFiles (Span< const CopyOperation > sourceDestination) |
| Copies many files. | |
| Result | copyFile (StringSpan source, StringSpan destination, CopyFlags copyFlags=CopyFlags()) |
| Copy a single file. | |
| Result | copyDirectories (Span< const CopyOperation > sourceDestination) |
| Copy many directories. | |
| Result | copyDirectory (StringSpan source, StringSpan destination, CopyFlags copyFlags=CopyFlags()) |
| Copy a single directory. | |
| Result | rename (StringSpan path, StringSpan newPath) |
| Rename a file or directory. | |
| Result | removeFiles (Span< const StringSpan > files) |
| Remove multiple files. | |
| Result | removeFile (StringSpan source) |
| Remove a single file. | |
| Result | removeFileIfExists (StringSpan source) |
| Remove a single file, giving no error if it doesn't exist. | |
| Result | removeLinkIfExists (StringSpan source) |
| Remove a single link, giving no error if it doesn't exist. | |
| Result | removeDirectoriesRecursive (Span< const StringSpan > directories) |
Remove multiple directories with their entire content (like posix rm -rf) | |
| Result | removeDirectoryRecursive (StringSpan directory) |
Remove single directory with its entire content (like posix rm -rf) | |
| Result | removeEmptyDirectories (Span< const StringSpan > directories) |
| Removes multiple empty directories. | |
| Result | removeEmptyDirectory (StringSpan directory) |
| Removes an empty directory. | |
| Result | makeDirectories (Span< const StringSpan > directories) |
| Creates new directories that do not already exist. | |
| Result | makeDirectory (StringSpan directory) |
| Creates a new directory that does not already exist. | |
| Result | makeDirectoriesIfNotExists (Span< const StringSpan > directories) |
| Creates new directories, if they don't already exist at the given path. | |
| Result | makeDirectoryIfNotExists (StringSpan directory) |
| Creates a new directory, if it doesn't already exists at the given path. | |
| Result | makeDirectoriesRecursive (Span< const StringSpan > directories) |
Create new directories, creating also intermediate non existing directories (like posix mkdir -p) | |
| Result | makeDirectoryRecursive (StringSpan directory) |
Create a new directory, creating also intermediate non existing directories (like posix mkdir -p) | |
| Result | createSymbolicLink (StringSpan sourceFileOrDirectory, StringSpan linkFile) |
| Creates a symbolic link at location linkFile pointing at sourceFileOrDirectory. | |
| Result | createHardLink (StringSpan sourceFile, StringSpan linkFile) |
| Creates a hard link at location linkFile pointing at sourceFile. | |
| bool | exists (StringSpan fileOrDirectory) |
| Check if a file or directory exists at a given path. | |
| bool | existsAndIsDirectory (StringSpan directory) |
| Check if a directory exists at given path. | |
| bool | existsAndIsFile (StringSpan file) |
| Check if a file exists at given path. | |
| bool | existsAndIsLink (StringSpan file) |
| Check if a link exists at given path. | |
| bool | canAccess (StringSpan fileOrDirectory, AccessMode accessMode=AccessMode::Exists) |
| Check whether the current process can access a path with the requested mode. | |
| bool | moveDirectory (StringSpan sourceDirectory, StringSpan destinationDirectory) |
| Moves a directory from source to destination. | |
| Result | write (StringSpan file, Span< const char > data) |
| Writes a block of memory to a file. | |
| Result | write (StringSpan file, Span< const uint8_t > data) |
| Result | writeString (StringSpan file, StringSpan text) |
| Replace the entire content of a file with the provided StringSpan. | |
| Result | writeStringAppend (StringSpan file, StringSpan text) |
| Appends a StringSpan to a file. | |
| template<typename T > | |
| Result | read (StringSpan file, T &data) |
| Read contents of a file into a String or Buffer. | |
| Result | read (StringSpan file, IGrowableBuffer &&buffer) |
| Read contents of a file into an IGrowableBuffer. | |
| Result | stat (StringSpan file, FileStat &fileStat) |
| Obtains richer metadata about a path, following symbolic links. | |
| Result | lstat (StringSpan file, FileStat &fileStat) |
| Obtains richer metadata about a path without following symbolic links. | |
| Result | getFileStat (StringSpan file, FileStat &fileStat) |
| Legacy convenience alias for stat(StringSpan, FileStat&) | |
| Result | readSymbolicLink (StringSpan linkFile, StringPath &destination) |
| Reads the target path stored by a symbolic link. | |
| Result | chmod (StringSpan path, uint32_t mode) |
| Change file permission bits for a path, following symbolic links. | |
| Result | chown (StringSpan path, uint32_t uid, uint32_t gid) |
| Change owner and group for a path, following symbolic links. | |
| Result | lchown (StringSpan path, uint32_t uid, uint32_t gid) |
| Change owner and group for a path without following symbolic links. | |
| Result | lchmod (StringSpan path, uint32_t mode) |
| Change file permission bits for a symbolic link without following it. | |
| Result | setLastModifiedTime (StringSpan file, TimeMs time) |
| Change last modified time of a given file. | |
Public Attributes | |
| bool | preciseErrorMessages = false |
| Formats errors in an internal buffer when returning failed Result. | |
Execute fs operations { exists, copy, delete } for { files and directories }.
It will scope all operations on relative paths to the initialWorkingDirectory passed in SC::FileSystem::init. All methods can always return failure due to access or disk I/O errors, and they will be omitted in the return clauses for each method. Only the specific returned result behaviour of the given method will be described.
Access mode for path checks.
Specify copy options like overwriting existing files.
A structure to describe modified time.
|
nodiscard |
Check whether the current process can access a path with the requested mode.
| fileOrDirectory | Path to check |
| accessMode | Requested access mode |
true if the requested access is allowed | Result SC::FileSystem::changeDirectory | ( | StringSpan | newDirectory | ) |
Changes current directory.
All operations with relative paths will be relative to this directory.
| newDirectory | The wanted directory |
initialWorkingDirectory exists and it's accessible | Result SC::FileSystem::chmod | ( | StringSpan | path, |
| uint32_t | mode ) |
| Result SC::FileSystem::chown | ( | StringSpan | path, |
| uint32_t | uid, | ||
| uint32_t | gid ) |
| Result SC::FileSystem::copyDirectories | ( | Span< const CopyOperation > | sourceDestination | ) |
Copy many directories.
| sourceDestination | View over a sequence of CopyOperation describing copies to be done |
|
inline |
Copy a single directory.
| source | Source directory path |
| destination | Destination directory path |
| copyFlags | Copy flags (overwrite, use clone api etc.) |
Example:
|
inline |
Copy a single file.
| source | Source file path |
| destination | Destination file path |
| copyFlags | Copy flags (overwrite, use clone api etc.) |
Example:
| Result SC::FileSystem::copyFiles | ( | Span< const CopyOperation > | sourceDestination | ) |
Copies many files.
| sourceDestination | View over a sequence of CopyOperation describing copies to be done |
Example:
| Result SC::FileSystem::createHardLink | ( | StringSpan | sourceFile, |
| StringSpan | linkFile ) |
Creates a hard link at location linkFile pointing at sourceFile.
| sourceFile | The target file of the hard link |
| linkFile | The location where the hard link will be created |
| Result SC::FileSystem::createSymbolicLink | ( | StringSpan | sourceFileOrDirectory, |
| StringSpan | linkFile ) |
Creates a symbolic link at location linkFile pointing at sourceFileOrDirectory.
| sourceFileOrDirectory | The target of the link (can be a folder or directory) |
| linkFile | The location where the symbolic link will be created |
|
nodiscard |
Check if a file or directory exists at a given path.
| fileOrDirectory | Path to check |
true if a file or directory exists at the given path
|
nodiscard |
Check if a directory exists at given path.
| directory | Directory path to check |
true if a directory exists at the given path
|
nodiscard |
Check if a file exists at given path.
| file | File path to check |
true if a file exists at the given pathExample:
|
nodiscard |
Check if a link exists at given path.
| file | Link path to check |
true if a file exists at the given path | Result SC::FileSystem::getFileStat | ( | StringSpan | file, |
| FileStat & | fileStat ) |
Legacy convenience alias for stat(StringSpan, FileStat&)
| file | Path to the file of interest | |
| [out] | fileStat | Destination structure that will receive statistics about the file |
| Result SC::FileSystem::init | ( | StringSpan | initialDirectory | ) |
Call init function when instantiating the class to set directory for all operations using relative paths.
| initialDirectory | The wanted directory |
initialDirectory exists and it's accessible | Result SC::FileSystem::lchmod | ( | StringSpan | path, |
| uint32_t | mode ) |
| Result SC::FileSystem::lchown | ( | StringSpan | path, |
| uint32_t | uid, | ||
| uint32_t | gid ) |
| Result SC::FileSystem::lstat | ( | StringSpan | file, |
| FileStat & | fileStat ) |
| Result SC::FileSystem::makeDirectories | ( | Span< const StringSpan > | directories | ) |
Creates new directories that do not already exist.
| directories | List of paths where to create such directories |
| Result SC::FileSystem::makeDirectoriesIfNotExists | ( | Span< const StringSpan > | directories | ) |
Creates new directories, if they don't already exist at the given path.
| directories | List of paths where to create such directories |
| Result SC::FileSystem::makeDirectoriesRecursive | ( | Span< const StringSpan > | directories | ) |
Create new directories, creating also intermediate non existing directories (like posix mkdir -p)
| directories | List of paths where to create such directories |
|
inline |
Creates a new directory that does not already exist.
| directory | Path where the directory should be created |
|
inline |
Creates a new directory, if it doesn't already exists at the given path.
| directory | Path where to create the new directory |
|
inline |
Create a new directory, creating also intermediate non existing directories (like posix mkdir -p)
| directory | Path where to create such directory |
|
nodiscard |
Moves a directory from source to destination.
| sourceDirectory | The source directory that will be moved to destination |
| destinationDirectory | The destination directory |
true if the move succeeded | Result SC::FileSystem::read | ( | StringSpan | file, |
| IGrowableBuffer && | buffer ) |
|
inline |
| Result SC::FileSystem::readSymbolicLink | ( | StringSpan | linkFile, |
| StringPath & | destination ) |
| Result SC::FileSystem::removeDirectoriesRecursive | ( | Span< const StringSpan > | directories | ) |
Remove multiple directories with their entire content (like posix rm -rf)
| directories | List of directories to remove |
|
inline |
Remove single directory with its entire content (like posix rm -rf)
| directory | Directory to remove |
Example:
| Result SC::FileSystem::removeEmptyDirectories | ( | Span< const StringSpan > | directories | ) |
Removes multiple empty directories.
| directories | List of empty directories to remove |
|
inline |
Removes an empty directory.
| directory | Empty directory to remove |
|
inline |
| Result SC::FileSystem::removeFileIfExists | ( | StringSpan | source | ) |
Remove a single file, giving no error if it doesn't exist.
| source | The file to be removed if it exists |
| Result SC::FileSystem::removeFiles | ( | Span< const StringSpan > | files | ) |
Remove multiple files.
| files | View over a list of paths |
| Result SC::FileSystem::removeLinkIfExists | ( | StringSpan | source | ) |
Remove a single link, giving no error if it doesn't exist.
| source | The link to be removed if it exists |
| Result SC::FileSystem::rename | ( | StringSpan | path, |
| StringSpan | newPath ) |
Rename a file or directory.
| path | The path to the file or directory to rename |
| newPath | The new path to the file or directory |
Example:
| Result SC::FileSystem::setLastModifiedTime | ( | StringSpan | file, |
| TimeMs | time ) |
| Result SC::FileSystem::stat | ( | StringSpan | file, |
| FileStat & | fileStat ) |
| Result SC::FileSystem::write | ( | StringSpan | file, |
| Span< const char > | data ) |
Writes a block of memory to a file.
| file | Path to the file that is meant to be written |
| data | Block of memory to write |
Example:
| Result SC::FileSystem::writeString | ( | StringSpan | file, |
| StringSpan | text ) |
Replace the entire content of a file with the provided StringSpan.
| file | Path to the file that is meant to be written |
| text | Text to be written |
| Result SC::FileSystem::writeStringAppend | ( | StringSpan | file, |
| StringSpan | text ) |
Appends a StringSpan to a file.
| file | Path to the file that is meant to be appended |
| text | Text to be appended |
| bool SC::FileSystem::preciseErrorMessages = false |
Formats errors in an internal buffer when returning failed Result.