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... | |
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 (StringView initialDirectory) |
Call init function when instantiating the class to set directory for all operations using relative paths. | |
Result | changeDirectory (StringView newDirectory) |
Changes current directory. | |
Result | copyFiles (Span< const CopyOperation > sourceDestination) |
Copies many files. | |
Result | copyFile (StringView source, StringView destination, CopyFlags copyFlags=CopyFlags()) |
Copy a single file. | |
Result | copyDirectories (Span< const CopyOperation > sourceDestination) |
Copy many directories. | |
Result | copyDirectory (StringView source, StringView destination, CopyFlags copyFlags=CopyFlags()) |
Copy a single directory. | |
Result | rename (StringView path, StringView newPath) |
Rename a file or directory. | |
Result | removeFiles (Span< const StringView > files) |
Remove multiple files. | |
Result | removeFile (StringView source) |
Remove a single file. | |
Result | removeFileIfExists (StringView source) |
Remove a single file, giving no error if it doesn't exist. | |
Result | removeLinkIfExists (StringView source) |
Remove a single link, giving no error if it doesn't exist. | |
Result | removeDirectoriesRecursive (Span< const StringView > directories) |
Remove multiple directories with their entire content (like posix rm -rf ) | |
Result | removeDirectoryRecursive (StringView directory) |
Remove single directory with its entire content (like posix rm -rf ) | |
Result | removeEmptyDirectories (Span< const StringView > directories) |
Removes multiple empty directories. | |
Result | removeEmptyDirectory (StringView directory) |
Removes an empty directory. | |
Result | removeEmptyDirectoriesRecursive (Span< const StringView > directories) |
Removes multiple empty directories that only contains other empty directories (but no files) | |
Result | removeEmptyDirectoryRecursive (StringView directory) |
Removes an empty directory that only contains other empty directories (but no files) | |
Result | makeDirectories (Span< const StringView > directories) |
Creates new directories that do not already exist. | |
Result | makeDirectory (StringView directory) |
Creates a new directory that does not already exist. | |
Result | makeDirectoriesIfNotExists (Span< const StringView > directories) |
Creates new directories, if they don't already exist at the given path. | |
Result | makeDirectoryIfNotExists (StringView directory) |
Creates a new directory, if it doesn't already exists at the given path. | |
Result | makeDirectoriesRecursive (Span< const StringView > directories) |
Create new directories, creating also intermediate non existing directories (like posix mkdir -p ) | |
Result | makeDirectoryRecursive (StringView directory) |
Create a new directory, creating also intermediate non existing directories (like posix mkdir -p ) | |
Result | createSymbolicLink (StringView sourceFileOrDirectory, StringView linkFile) |
Creates a symbolic link at location linkFile pointing at sourceFileOrDirectory. | |
bool | exists (StringView fileOrDirectory) |
Check if a file or directory exists at a given path. | |
bool | existsAndIsDirectory (StringView directory) |
Check if a directory exists at given path. | |
bool | existsAndIsFile (StringView file) |
Check if a file exists at given path. | |
bool | existsAndIsLink (StringView file) |
Check if a link exists at given path. | |
bool | moveDirectory (StringView sourceDirectory, StringView destinationDirectory) |
Moves a directory from source to destination. | |
Result | write (StringView file, Span< const char > data) |
Writes a block of memory to a file. | |
Result | write (StringView file, Span< const uint8_t > data) |
Result | read (StringView file, Buffer &data) |
Reads contents of a file into a SC::Buffer. | |
Result | writeString (StringView file, StringView text) |
Replace the entire content of a file with the provided StringView. | |
Result | writeStringAppend (StringView file, StringView text) |
Appends a StringView to a file. | |
Result | read (StringView file, String &data, StringEncoding encoding) |
Read contents of a file into a string with given encoding. | |
Result | getFileStat (StringView file, FileStat &fileStat) |
Obtains stats (size, modified time) about a file. | |
Result | setLastModifiedTime (StringView 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 | ( | StringView | 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
|
nodiscard |
Copy many directories.
sourceDestination | View over a sequence of CopyOperation describing copies to be done |
|
inlinenodiscard |
Copy a single directory.
source | Source directory path |
destination | Destination directory path |
copyFlags | Copy flags (overwrite, use clone api etc.) |
Example:
|
inlinenodiscard |
Copy a single file.
source | Source file path |
destination | Destination file path |
copyFlags | Copy flags (overwrite, use clone api etc.) |
Example:
|
nodiscard |
Copies many files.
sourceDestination | View over a sequence of CopyOperation describing copies to be done |
Example:
|
nodiscard |
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
|
nodiscard |
Result SC::FileSystem::init | ( | StringView | 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
|
nodiscard |
Creates new directories that do not already exist.
directories | List of paths where to create such directories |
|
nodiscard |
Creates new directories, if they don't already exist at the given path.
directories | List of paths where to create such directories |
|
nodiscard |
Create new directories, creating also intermediate non existing directories (like posix mkdir -p
)
directories | List of paths where to create such directories |
|
inlinenodiscard |
Creates a new directory that does not already exist.
directory | Path where the directory should be created |
|
inlinenodiscard |
Creates a new directory, if it doesn't already exists at the given path.
directory | Path where to create the new directory |
|
inlinenodiscard |
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
|
nodiscard |
Reads contents of a file into a SC::Buffer.
file | Path to the file to read | |
[out] | data | Destination buffer that will receive data |
|
nodiscard |
|
nodiscard |
Remove multiple directories with their entire content (like posix rm -rf
)
directories | List of directories to remove |
|
inlinenodiscard |
Remove single directory with its entire content (like posix rm -rf
)
directory | Directory to remove |
Example:
|
nodiscard |
Removes multiple empty directories.
directories | List of empty directories to remove |
|
nodiscard |
Removes multiple empty directories that only contains other empty directories (but no files)
directories | List of empty directories to remove |
|
inlinenodiscard |
Removes an empty directory.
directory | Empty directory to remove |
|
inlinenodiscard |
Removes an empty directory that only contains other empty directories (but no files)
directory | List of empty directories to remove |
|
inlinenodiscard |
|
nodiscard |
Remove a single file, giving no error if it doesn't exist.
source | The file to be removed if it exists |
|
nodiscard |
Remove multiple files.
files | View over a list of paths |
|
nodiscard |
Remove a single link, giving no error if it doesn't exist.
source | The link to be removed if it exists |
|
nodiscard |
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:
|
nodiscard |
|
nodiscard |
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:
|
nodiscard |
Replace the entire content of a file with the provided StringView.
file | Path to the file that is meant to be written |
text | Text to be written |
|
nodiscard |
Appends a StringView 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.