class FileSystem

Utility class for dealing with files.

Public

Methods

staticOpenFile

static SPtr<DataStream> OpenFile(const Path &fullPath, bool readOnly = true)

Opens a file and returns a data stream capable of reading or writing to that file.

fullPath
Full path to a file.
readOnly
(optional) If true, returned stream will only be readable.

staticCreateAndOpenFile

static SPtr<DataStream> CreateAndOpenFile(const Path &fullPath)

Opens a file and returns a data stream capable of reading and writing to that file.

If file doesn't exist new one will be created.

fullPath
Full path to a file.

staticGetFileSize

static u64 GetFileSize(const Path &fullPath)

Returns the size of a file in bytes.

fullPath
Full path to a file.

staticRemove

static bool Remove(const Path &fullPath, bool recursively = true)

Deletes a file or a folder at the specified path.

fullPath
Full path to a file or a folder..
recursively
(optional) If true, folders will have their contents deleted as well. Otherwise an exception will be thrown for non-empty folders.

staticMove

static bool Move(const Path &oldPath, const Path &newPath, bool overwriteExisting = true)

Moves a file or a folder from one to another path.

This can also be used as a rename operation.

oldPath
Full path to the old file/folder.
newPath
Full path to the new file/folder.
overwriteExisting
(optional) If true, any existing file/folder at the new location will be overwritten, otherwise an exception will be thrown if a file/folder already exists.

staticCopy

static bool Copy(const Path &oldPath, const Path &newPath, bool overwriteExisting = true)

Makes a copy of a file or a folder in the specified path.

oldPath
Full path to the old file/folder.
newPath
Full path to the new file/folder.
overwriteExisting
(optional) If true, any existing file/folder at the new location will be overwritten, otherwise an exception will be thrown if a file/folder already exists.

staticCreateFolder

static bool CreateFolder(const Path &fullPath)

Creates a folder at the specified path.

fullPath
Full path to a full folder to create.

staticExists

static bool Exists(const Path &fullPath)

Returns true if a file or a folder exists at the specified path.

fullPath
Full path to a file or folder.

staticIsFile

static bool IsFile(const Path &fullPath)

Returns true if a file exists at the specified path.

fullPath
Full path to a file or folder.

staticIsFolder

static bool IsFolder(const Path &fullPath)

Returns true if a folder exists at the specified path.

fullPath
Full path to a file or folder.

staticGetChildren

static void GetChildren(const Path &dirPath, Vector<Path> &outFiles, Vector<Path> &outDirectories)

Returns all files or folders located in the specified folder.

dirPath
Full path to the folder to retrieve children files/folders from.
outFiles
Full paths to all files located directly in specified folder.
outDirectories
Full paths to all folders located directly in specified folder.

staticIterate

static bool Iterate(const Path &dirPath, std::function<bool (const Path &)> fileCallback, std::function<bool (const Path &)> dirCallback = nullptr, bool recursive = true)

Iterates over all files and directories in the specified folder and calls the provided callback when a file/folder is iterated over.

dirPath
Directory over which to iterate
fileCallback
Callback to call whenever a file is found. If callback returns false iteration stops. Can be null.
dirCallback
Callback to call whenever a directory is found. If callback returns false iteration stops. Can be null.
recursive
If false then only the direct children of the provided folder will be iterated over, and if true then child directories will be recursively visited as well.

Returns: True if iteration finished iterating over all files/folders, or false if it was interrupted by a callback returning false.

staticGetLastModifiedTime

static std::time_t GetLastModifiedTime(const Path &fullPath)

Returns the last modified time of a file or a folder at the specified path.

fullPath
Full path to a file or a folder.

staticGetExecutableFolderPath

static Path GetExecutableFolderPath()

Returns the path to the directory containing the current executable.

staticGetWorkingDirectoryPath

static Path GetWorkingDirectoryPath()

Returns the path to the current working directory.

staticGetTemporaryFolderPath

static Path GetTemporaryFolderPath()

Returns the path to a directory where temporary files may be stored.

staticGetUniqueTemporaryFilePath

static Path GetUniqueTemporaryFilePath()

Returns a path to a file in the temporary directory.

The path is guaranteed not to exist currently in the directory.

staticGetApplicationDataFolder

static Path GetApplicationDataFolder()

Returns the application data folder for the current user.

Private

Methods

staticCopyFile

static bool CopyFile(const Path &oldPath, const Path &newPath)

Copy a single file.

Internal function used by copy().

staticRemoveFile

static bool RemoveFile(const Path &path)

Remove a single file.

Internal function used by remove().

staticMoveFile

static bool MoveFile(const Path &oldPath, const Path &newPath)

Move a single file.

Internal function used by move().