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 | 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. | |
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 | 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 | getFileStat (StringSpan file, FileStat &fileStat) |
Obtains stats (size, modified time) about a file. | |
Result | setLastModifiedTime (StringSpan file, Time::Realtime 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.
Specify copy options like overwriting existing files.
A structure to describe modified time.
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::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::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 ) |
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::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
|
inline |
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, |
Time::Realtime | time ) |
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.