4#include "../Foundation/Result.h"
5#include "../Strings/SmallString.h"
6#include "../Time/Time.h"
11struct StringConverter;
48 useCloneIfSupported =
true;
65 useCloneIfSupported = value;
72 bool useCloneIfSupported;
325 Result formatError(
int errorNumber,
StringView item,
bool isWindowsNativeError);
329 [[nodiscard]]
static Result fallbackCopyDirectory(
String& sourceDirectory,
String& destinationDirectory,
331 [[nodiscard]]
static Result fallbackRemoveDirectoryRecursive(
String& sourceDirectory);
#define SC_COMPILER_EXPORT
Macro for symbol visibility in non-MSVC compilers.
Definition: Compiler.h:78
StringEncoding
String Encoding (Ascii, Utf8, Utf16)
Definition: StringIterator.h:17
@ Native
Encoding is UTF8.
Specify copy options like overwriting existing files.
Definition: FileSystem.h:44
CopyFlags & setUseCloneIfSupported(bool value)
If true copy will use native filesystem clone os api.
Definition: FileSystem.h:63
CopyFlags & setOverwrite(bool value)
If true copy will overwrite existing files in the destination.
Definition: FileSystem.h:54
Specify source, destination and flags for a copy operation.
Definition: FileSystem.h:77
StringView destination
Copy operation sink (can be a {relative | absolute} {file | directory} path)
Definition: FileSystem.h:79
CopyFlags copyFlags
Copy operation flags (overwrite, use clone api etc.)
Definition: FileSystem.h:80
StringView source
Copy operation source (can be a {relative | absolute} {file | directory} path)
Definition: FileSystem.h:78
A structure to describe modified time.
Definition: FileSystem.h:302
Time::Absolute modifiedTime
Time when file was last modified.
Definition: FileSystem.h:304
Execute fs operations { exists, copy, delete } for { files and directories }.
Definition: FileSystem.h:25
Result createSymbolicLink(StringView sourceFileOrDirectory, StringView linkFile)
Creates a symbolic link at location linkFile pointing at sourceFileOrDirectory.
Result changeDirectory(StringView newDirectory)
Changes current directory.
Result removeEmptyDirectories(Span< const StringView > directories)
Removes multiple empty directories.
bool existsAndIsFile(StringView file)
Check if a file exists at given path.
Result copyDirectory(StringView source, StringView destination, CopyFlags copyFlags=CopyFlags())
Copy a single directory.
Definition: FileSystem.h:118
Result setLastModifiedTime(StringView file, Time::Absolute time)
Change last modified time of a given file.
Result writeString(StringView file, StringView text)
Replace the entire content of a file with the provided StringView.
Result removeFile(StringView source)
Remove a single file.
Definition: FileSystem.h:132
Result removeEmptyDirectoryRecursive(StringView directory)
Removes an empty directory that only contains other empty directories (but no files)
Definition: FileSystem.h:183
Result makeDirectoriesRecursive(Span< const StringView > directories)
Create new directories, creating also intermediate non existing directories (like posix mkdir -p)
Result init(StringView initialDirectory)
Call init function when instantiating the class to set directory for all operations using relative pa...
Result copyFiles(Span< const CopyOperation > sourceDestination)
Copies many files.
bool exists(StringView fileOrDirectory)
Check if a file or directory exists at a given path.
Result makeDirectories(Span< const StringView > directories)
Creates new directories that do not already exist.
Result read(StringView file, Vector< char > &data)
Reads contents of a file into a SC::Vector buffer.
Result write(StringView file, Span< const char > data)
Writes a block of memory to a file.
Result getFileStat(StringView file, FileStat &fileStat)
Obtains stats (size, modified time) about a file.
Result removeEmptyDirectoriesRecursive(Span< const StringView > directories)
Removes multiple empty directories that only contains other empty directories (but no files)
bool existsAndIsLink(StringView file)
Check if a link exists at given path.
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 removeDirectoryRecursive(StringView directory)
Remove single directory with its entire content (like posix rm -rf)
Definition: FileSystem.h:156
Result removeEmptyDirectory(StringView directory)
Removes an empty directory.
Definition: FileSystem.h:171
Result removeFiles(Span< const StringView > files)
Remove multiple files.
Result writeStringAppend(StringView file, StringView text)
Appends a StringView to a file.
bool existsAndIsDirectory(StringView directory)
Check if a directory exists at given path.
bool preciseErrorMessages
Formats errors in an internal buffer when returning failed Result.
Definition: FileSystem.h:30
Result copyDirectories(Span< const CopyOperation > sourceDestination)
Copy many directories.
bool moveDirectory(StringView sourceDirectory, StringView destinationDirectory)
Moves a directory from source to destination.
Result copyFile(StringView source, StringView destination, CopyFlags copyFlags=CopyFlags())
Copy a single file.
Definition: FileSystem.h:99
Result makeDirectoryRecursive(StringView directory)
Create a new directory, creating also intermediate non existing directories (like posix mkdir -p)
Definition: FileSystem.h:223
Result makeDirectory(StringView directory)
Creates a new directory that does not already exist.
Definition: FileSystem.h:198
Result removeDirectoriesRecursive(Span< const StringView > directories)
Remove multiple directories with their entire content (like posix rm -rf)
Result read(StringView file, String &data, StringEncoding encoding)
Read contents of a file into a string with given encoding.
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.
Definition: FileSystem.h:208
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition: Result.h:11
String with compile time configurable inline storage (small string optimization)
Definition: SmallString.h:21
View over a contiguous sequence of items (pointer + size in elements).
Definition: Span.h:20
A non-modifiable owning string with associated encoding.
Definition: String.h:30
Non-owning view over a range of characters with UTF Encoding.
Definition: StringView.h:47
Absolute time represented with milliseconds since epoch.
Definition: Time.h:74
A contiguous sequence of heap allocated elements.
Definition: Vector.h:51