Execute fs operations { exists, copy, delete } for { files and directories }. More...
#include <FileSystem.h>
Classes | |
struct | CopyFlags |
Specify copy options like overwriting existing files. More... | |
struct | CopyOperation |
Specify source, destination and flags for a copy operation. More... | |
struct | FileStat |
A structure to describe modified time. More... | |
Public Member Functions | |
Result | init (StringView initialDirectory) |
Call init function when instantiating the class to set directory for all operations using relative paths. More... | |
Result | changeDirectory (StringView newDirectory) |
Changes current directory. More... | |
Result | copyFiles (Span< const CopyOperation > sourceDestination) |
Copies many files. More... | |
Result | copyFile (StringView source, StringView destination, CopyFlags copyFlags=CopyFlags()) |
Copy a single file. More... | |
Result | copyDirectories (Span< const CopyOperation > sourceDestination) |
Copy many directories. More... | |
Result | copyDirectory (StringView source, StringView destination, CopyFlags copyFlags=CopyFlags()) |
Copy a single directory. More... | |
Result | removeFiles (Span< const StringView > files) |
Remove multiple files. More... | |
Result | removeFile (StringView source) |
Remove a single file. More... | |
Result | removeFileIfExists (StringView source) |
Remove a single file, giving no error if it doesn't exist. More... | |
Result | removeLinkIfExists (StringView source) |
Remove a single link, giving no error if it doesn't exist. More... | |
Result | removeDirectoriesRecursive (Span< const StringView > directories) |
Remove multiple directories with their entire content (like posix rm -rf ) More... | |
Result | removeDirectoryRecursive (StringView directory) |
Remove single directory with its entire content (like posix rm -rf ) More... | |
Result | removeEmptyDirectories (Span< const StringView > directories) |
Removes multiple empty directories. More... | |
Result | removeEmptyDirectory (StringView directory) |
Removes an empty directory. More... | |
Result | removeEmptyDirectoriesRecursive (Span< const StringView > directories) |
Removes multiple empty directories that only contains other empty directories (but no files) More... | |
Result | removeEmptyDirectoryRecursive (StringView directory) |
Removes an empty directory that only contains other empty directories (but no files) More... | |
Result | makeDirectories (Span< const StringView > directories) |
Creates new directories that do not already exist. More... | |
Result | makeDirectory (StringView directory) |
Creates a new directory that does not already exist. More... | |
Result | makeDirectoriesIfNotExists (Span< const StringView > directories) |
Creates new directories, if they don't already exist at the given path. More... | |
Result | makeDirectoryIfNotExists (StringView directory) |
Creates a new directory, if it doesn't already exists at the given path. More... | |
Result | makeDirectoriesRecursive (Span< const StringView > directories) |
Create new directories, creating also intermediate non existing directories (like posix mkdir -p ) More... | |
Result | makeDirectoryRecursive (StringView directory) |
Create a new directory, creating also intermediate non existing directories (like posix mkdir -p ) More... | |
Result | createSymbolicLink (StringView sourceFileOrDirectory, StringView linkFile) |
Creates a symbolic link at location linkFile pointing at sourceFileOrDirectory. More... | |
bool | exists (StringView fileOrDirectory) |
Check if a file or directory exists at a given path. More... | |
bool | existsAndIsDirectory (StringView directory) |
Check if a directory exists at given path. More... | |
bool | existsAndIsFile (StringView file) |
Check if a file exists at given path. More... | |
bool | existsAndIsLink (StringView file) |
Check if a link exists at given path. More... | |
bool | moveDirectory (StringView sourceDirectory, StringView destinationDirectory) |
Moves a directory from source to destination. More... | |
Result | write (StringView file, Span< const char > data) |
Writes a block of memory to a file. More... | |
Result | write (StringView file, Span< const uint8_t > data) |
Result | read (StringView file, Vector< char > &data) |
Reads contents of a file into a SC::Vector buffer. More... | |
Result | read (StringView file, Vector< uint8_t > &data) |
Result | writeString (StringView file, StringView text) |
Replace the entire content of a file with the provided StringView. More... | |
Result | writeStringAppend (StringView file, StringView text) |
Appends a StringView to a file. More... | |
Result | read (StringView file, String &data, StringEncoding encoding) |
Read contents of a file into a string with given encoding. More... | |
Result | getFileStat (StringView file, FileStat &fileStat) |
Obtains stats (size, modified time) about a file. More... | |
Result | setLastModifiedTime (StringView file, Time::Absolute time) |
Change last modified time of a given file. More... | |
Public Attributes | |
bool | preciseErrorMessages = false |
Formats errors in an internal buffer when returning failed Result. More... | |
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.
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 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 | ( | StringView | sourceFileOrDirectory, |
StringView | 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 |
bool SC::FileSystem::exists | ( | StringView | fileOrDirectory | ) |
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 bool SC::FileSystem::existsAndIsDirectory | ( | StringView | directory | ) |
Check if a directory exists at given path.
directory | Directory path to check |
true
if a directory exists at the given path bool SC::FileSystem::existsAndIsFile | ( | StringView | file | ) |
Check if a file exists at given path.
file | File path to check |
true
if a file exists at the given pathExample:
bool SC::FileSystem::existsAndIsLink | ( | StringView | file | ) |
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 | ( | StringView | file, |
FileStat & | fileStat | ||
) |
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 Result SC::FileSystem::makeDirectories | ( | Span< const StringView > | directories | ) |
Creates new directories that do not already exist.
directories | List of paths where to create such directories |
Result SC::FileSystem::makeDirectoriesIfNotExists | ( | Span< const StringView > | 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 StringView > | 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 |
bool SC::FileSystem::moveDirectory | ( | StringView | sourceDirectory, |
StringView | destinationDirectory | ||
) |
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 | ( | StringView | file, |
String & | data, | ||
StringEncoding | encoding | ||
) |
Result SC::FileSystem::read | ( | StringView | file, |
Vector< char > & | data | ||
) |
Reads contents of a file into a SC::Vector buffer.
file | Path to the file to read | |
[out] | data | Destination buffer that will receive data |
Result SC::FileSystem::removeDirectoriesRecursive | ( | Span< const StringView > | 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 StringView > | directories | ) |
Removes multiple empty directories.
directories | List of empty directories to remove |
Result SC::FileSystem::removeEmptyDirectoriesRecursive | ( | Span< const StringView > | directories | ) |
Removes multiple empty directories that only contains other empty directories (but no files)
directories | List of empty directories to remove |
|
inline |
Removes an empty directory.
directory | Empty directory to remove |
|
inline |
Removes an empty directory that only contains other empty directories (but no files)
directory | List of empty directories to remove |
|
inline |
Result SC::FileSystem::removeFileIfExists | ( | StringView | 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 StringView > | files | ) |
Remove multiple files.
files | View over a list of paths |
Result SC::FileSystem::removeLinkIfExists | ( | StringView | 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::setLastModifiedTime | ( | StringView | file, |
Time::Absolute | time | ||
) |
Result SC::FileSystem::write | ( | StringView | 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 | ( | StringView | file, |
StringView | text | ||
) |
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 |
Result SC::FileSystem::writeStringAppend | ( | StringView | file, |
StringView | text | ||
) |
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.