4#include "../Foundation/Internal/IGrowableBuffer.h"
5#include "../Foundation/Result.h"
6#include "../Foundation/StringPath.h"
62 bool preciseErrorMessages =
false;
103 return copyFiles(
CopyOperation{source, destination, copyFlags});
122 return copyDirectories(
CopyOperation{source, destination, copyFlags});
280 template <
typename T>
283 return read(file, GrowableBuffer<T>{data});
343 char errorMessageBuffer[256] = {0};
345 Result formatError(
int errorNumber,
StringSpan item,
bool isWindowsNativeError);
A structure to describe copy flags.
Definition FileSystem.h:25
FileSystemCopyFlags & setUseCloneIfSupported(bool value)
If true copy will use native filesystem clone os api.
Definition FileSystem.h:44
FileSystemCopyFlags & setOverwrite(bool value)
If true copy will overwrite existing files in the destination.
Definition FileSystem.h:35
bool useCloneIfSupported
If true copy will use native filesystem clone os api.
Definition FileSystem.h:51
bool overwrite
If true copy will overwrite existing files in the destination.
Definition FileSystem.h:50
A structure to describe file stats.
Definition FileSystem.h:18
size_t fileSize
Size of the file in bytes.
Definition FileSystem.h:19
TimeMs modifiedTime
Time when file was last modified.
Definition FileSystem.h:20
Specify source, destination and flags for a copy operation.
Definition FileSystem.h:79
StringSpan destination
Copy operation sink (can be a {relative | absolute} {file | directory} path)
Definition FileSystem.h:81
CopyFlags copyFlags
Copy operation flags (overwrite, use clone api etc.)
Definition FileSystem.h:82
StringSpan source
Copy operation source (can be a {relative | absolute} {file | directory} path)
Definition FileSystem.h:80
Low level filesystem API, requiring paths in native encoding (UTF-16 on Windows, UTF-8 elsewhere)
Definition FileSystem.h:310
Execute fs operations { exists, copy, delete } for { files and directories }.
Definition FileSystem.h:61
bool existsAndIsFile(StringSpan file)
Check if a file exists at given path.
Result removeFiles(Span< const StringSpan > files)
Remove multiple files.
Result removeFile(StringSpan source)
Remove a single file.
Definition FileSystem.h:144
Result init(StringSpan initialDirectory)
Call init function when instantiating the class to set directory for all operations using relative pa...
Result read(StringSpan file, T &data)
Read contents of a file into a String or Buffer.
Definition FileSystem.h:281
Result changeDirectory(StringSpan newDirectory)
Changes current directory.
Result makeDirectoriesRecursive(Span< const StringSpan > directories)
Create new directories, creating also intermediate non existing directories (like posix mkdir -p)
Result removeLinkIfExists(StringSpan source)
Remove a single link, giving no error if it doesn't exist.
bool exists(StringSpan fileOrDirectory)
Check if a file or directory exists at a given path.
bool moveDirectory(StringSpan sourceDirectory, StringSpan destinationDirectory)
Moves a directory from source to destination.
Result removeDirectoriesRecursive(Span< const StringSpan > directories)
Remove multiple directories with their entire content (like posix rm -rf)
Result setLastModifiedTime(StringSpan file, TimeMs time)
Change last modified time of a given file.
Result copyFiles(Span< const CopyOperation > sourceDestination)
Copies many files.
Result removeEmptyDirectories(Span< const StringSpan > directories)
Removes multiple empty directories.
Result makeDirectoryRecursive(StringSpan directory)
Create a new directory, creating also intermediate non existing directories (like posix mkdir -p)
Definition FileSystem.h:214
bool existsAndIsDirectory(StringSpan directory)
Check if a directory exists at given path.
Result writeStringAppend(StringSpan file, StringSpan text)
Appends a StringSpan to a file.
Result getFileStat(StringSpan file, FileStat &fileStat)
Obtains stats (size, modified time) about a file.
Result removeFileIfExists(StringSpan source)
Remove a single file, giving no error if it doesn't exist.
Result rename(StringSpan path, StringSpan newPath)
Rename a file or directory.
Result makeDirectory(StringSpan directory)
Creates a new directory that does not already exist.
Definition FileSystem.h:192
Result removeDirectoryRecursive(StringSpan directory)
Remove single directory with its entire content (like posix rm -rf)
Definition FileSystem.h:168
Result makeDirectories(Span< const StringSpan > directories)
Creates new directories that do not already exist.
Result write(StringSpan file, Span< const char > data)
Writes a block of memory to a file.
Result read(StringSpan file, IGrowableBuffer &&buffer)
Read contents of a file into an IGrowableBuffer.
Result makeDirectoriesIfNotExists(Span< const StringSpan > directories)
Creates new directories, if they don't already exist at the given path.
Result copyDirectory(StringSpan source, StringSpan destination, CopyFlags copyFlags=CopyFlags())
Copy a single directory.
Definition FileSystem.h:120
Result createSymbolicLink(StringSpan sourceFileOrDirectory, StringSpan linkFile)
Creates a symbolic link at location linkFile pointing at sourceFileOrDirectory.
Result copyDirectories(Span< const CopyOperation > sourceDestination)
Copy many directories.
Result copyFile(StringSpan source, StringSpan destination, CopyFlags copyFlags=CopyFlags())
Copy a single file.
Definition FileSystem.h:101
Result makeDirectoryIfNotExists(StringSpan directory)
Creates a new directory, if it doesn't already exists at the given path.
Definition FileSystem.h:202
Result removeEmptyDirectory(StringSpan directory)
Removes an empty directory.
Definition FileSystem.h:180
bool existsAndIsLink(StringSpan file)
Check if a link exists at given path.
Result writeString(StringSpan file, StringSpan text)
Replace the entire content of a file with the provided StringSpan.
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
Pre-sized char array holding enough space to represent a file system path.
Definition StringPath.h:42
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37
A vocabulary type representing a time interval in milliseconds since epoch.
Definition PrimitiveTypes.h:63