Death::IO::FileSystem class

File system related methods.

Public types

class Directory
Handles directory traversal, should be used as iterator.
class MapDeleter
Memory-mapped file deleter.
enum class Permission { None = 0, Read = 0x01, Write = 0x02, Execute = 0x04 }
Available permissions to check or set, supports a bitwise combination of its member values.
enum class EnumerationOptions { None = 0, SkipFiles = 0x01, SkipDirectories = 0x02, SkipSpecial = 0x04 }
Options that modify behavior of Directory, supports a bitwise combination of its member values.

Public static variables

static std::size_t MaxPathLength constexpr
static char PathSeparator constexpr

Public static functions

static auto FindPathCaseInsensitive(Containers::StringView path) -> Containers::String
Returns path with correct case on case-sensitive platforms (or nothing if path not found)
static auto FindPathCaseInsensitive(Containers::String&& path) -> Containers::String
static auto CombinePath(Containers::StringView first, Containers::StringView second) -> Containers::String
Combines together specified path components.
static auto CombinePath(Containers::ArrayView<const Containers::StringView> paths) -> Containers::String
static auto CombinePath(std::initializer_list<Containers::StringView> paths) -> Containers::String
static auto GetDirectoryName(Containers::StringView path) -> Containers::StringView
Returns the path up to, but not including, the final separator.
static auto GetFileName(Containers::StringView path) -> Containers::StringView
Returns the path component after the final separator.
static auto GetFileNameWithoutExtension(Containers::StringView path) -> Containers::StringView
Returns the path component after the final separator without extension.
static auto GetExtension(Containers::StringView path) -> Containers::String
Returns the extension as lower-case string without dot or empty string if it is not found.
static auto ToNativeSeparators(Containers::StringView path) -> Containers::StringView
Converts path using forward slashes to native separators.
static auto GetAbsolutePath(Containers::StringView path) -> Containers::String
Returns an absolute path from a relative one.
static auto IsAbsolutePath(Containers::StringView path) -> bool
Returns true if the specified path is not empty and is absolute.
static auto GetExecutablePath() -> Containers::String
Returns the path of executable.
static auto GetWorkingDirectory() -> Containers::String
Returns the path of current working directory.
static auto SetWorkingDirectory(Containers::StringView path) -> bool
Sets the current working directory, the starting point for interpreting relative paths.
static auto GetHomeDirectory() -> Containers::String
Returns the path of the user home directory.
static auto GetExternalStorage() -> Containers::String
Returns the path of the Android external storage directory.
static auto GetLocalStorage() -> Containers::String
Returns the path pointing to $XDG_DATA_HOME or ~/.local/share/ in the most cases.
static auto GetWindowsDirectory() -> Containers::String
Returns the path of Windows® directory.
static auto DirectoryExists(Containers::StringView path) -> bool
Returns true if the specified path is a directory.
static auto FileExists(Containers::StringView path) -> bool
Returns true if the specified path is a file.
static auto Exists(Containers::StringView path) -> bool
Returns true if the file or directory exists.
static auto IsReadable(Containers::StringView path) -> bool
Returns true if the file or directory is readable.
static auto IsWritable(Containers::StringView path) -> bool
Returns true if the file or directory is writeable.
static auto IsExecutable(Containers::StringView path) -> bool
Returns true if the file or directory is executable.
static auto IsReadableFile(Containers::StringView path) -> bool
Returns true if the path is a file and is readable.
static auto IsWritableFile(Containers::StringView path) -> bool
Returns true if the path is a file and is writeable.
static auto IsSymbolicLink(Containers::StringView path) -> bool
Returns true if the path is a symbolic link.
static auto IsHidden(Containers::StringView path) -> bool
Returns true if the file or directory is hidden.
static auto SetHidden(Containers::StringView path, bool hidden) -> bool
Makes a file or directory hidden or not.
static auto IsReadOnly(Containers::StringView path) -> bool
Returns true if the file or directory is read-only.
static auto SetReadOnly(Containers::StringView path, bool readonly) -> bool
Makes a file or directory read-only or not.
static auto CreateDirectories(Containers::StringView path) -> bool
Creates a new directory.
static auto RemoveDirectoryRecursive(Containers::StringView path) -> bool
Deletes an directory and all its content.
static auto RemoveFile(Containers::StringView path) -> bool
Deletes a file.
static auto Move(Containers::StringView oldPath, Containers::StringView newPath) -> bool
Renames or moves a file or a directory.
static auto MoveToTrash(Containers::StringView path) -> bool
Moves a file or a directory to trash.
static auto Copy(Containers::StringView oldPath, Containers::StringView newPath, bool overwrite = true) -> bool
Copies a file.
static auto GetFileSize(Containers::StringView path) -> std::int64_t
Returns the file size in bytes.
static auto GetCreationTime(Containers::StringView path) -> Containers::DateTime
Returns the creation time of the file or directory (if available)
static auto GetLastModificationTime(Containers::StringView path) -> Containers::DateTime
Returns the last time the file or directory was modified.
static auto GetLastAccessTime(Containers::StringView path) -> Containers::DateTime
Returns the last time the file or directory was accessed.
static auto GetPermissions(Containers::StringView path) -> Permission
Returns permissions of a given file or directory.
static auto ChangePermissions(Containers::StringView path, Permission mode) -> bool
Sets the file or directory permissions to those of the mask.
static auto AddPermissions(Containers::StringView path, Permission mode) -> bool
Adds permissions in the mask to a file or a directory.
static auto RemovePermissions(Containers::StringView path, Permission mode) -> bool
Removes permissions in the mask from a file or a directory.
static auto LaunchDirectoryAsync(Containers::StringView path) -> bool
Tries to open specified directory in operating system's file manager.
static void MountAsPersistent(Containers::StringView path)
Mounts specified path to persistent file system.
static void SyncToPersistent()
Saves all changes to all persistent file systems.
static auto Open(Containers::StringView path, FileAccess mode) -> std::unique_ptr<Stream>
Opens a file stream with specified access mode.
static auto OpenAsMemoryMapped(Containers::StringView path, FileAccess mode) -> std::optional<Containers::Array<char, MapDeleter>>
Maps a file for reading and writing.
static auto CreateFromMemory(std::uint8_t* bufferPtr, std::int32_t bufferSize) -> std::unique_ptr<Stream>
Creates a stream from a specified region of memory.
static auto CreateFromMemory(const std::uint8_t* bufferPtr, std::int32_t bufferSize) -> std::unique_ptr<Stream>
static auto GetSavePath(Containers::StringView applicationName) -> const Containers::String&
Returns application-specific writable directory for saving data.

Constructors, destructors, conversion operators

FileSystem() deleted
~FileSystem() deleted

Enum documentation

enum class Death::IO::FileSystem::Permission

Available permissions to check or set, supports a bitwise combination of its member values.

Enumerators
None

None

Read

Read

Write

Write

Execute

Execute

enum class Death::IO::FileSystem::EnumerationOptions

Options that modify behavior of Directory, supports a bitwise combination of its member values.

Enumerators
None

Default behavior.

SkipFiles

Skip regular files.

SkipDirectories

Skip directories.

SkipSpecial

Skip everything that is not a file or directory.

Function documentation

static Containers::String Death::IO::FileSystem::FindPathCaseInsensitive(Containers::String&& path)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

static Containers::String Death::IO::FileSystem::GetExternalStorage()

Returns the path of the Android external storage directory.

static Containers::String Death::IO::FileSystem::GetLocalStorage()

Returns the path pointing to $XDG_DATA_HOME or ~/.local/share/ in the most cases.

static Containers::String Death::IO::FileSystem::GetWindowsDirectory()

Returns the path of Windows® directory.

static void Death::IO::FileSystem::MountAsPersistent(Containers::StringView path)

Mounts specified path to persistent file system.

static void Death::IO::FileSystem::SyncToPersistent()

Saves all changes to all persistent file systems.

static std::optional<Containers::Array<char, MapDeleter>> Death::IO::FileSystem::OpenAsMemoryMapped(Containers::StringView path, FileAccess mode)

Maps a file for reading and writing.

Maps the file as a read-write memory. The array deleter takes care of unmapping. If the file doesn't exist or an error occurs while mapping, returns std::nullopt_t. If the file is empty it's only opened but not mapped and a zero-sized nullptr array is returned, with the deleter containing the open file handle.

static std::unique_ptr<Stream> Death::IO::FileSystem::CreateFromMemory(const std::uint8_t* bufferPtr, std::int32_t bufferSize)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.