class EE::System::FileSystem

Overview

#include <filesystem.hpp>

class FileSystem {
public:
    // methods

    static std::string getOSSlash();
    static bool fileExists(const std::string& Filepath);
    static bool fileGet(const std::string& path, std::vector<Uint8>& data);
    static bool fileGet(const std::string& path, ScopedBuffer& data);
    static bool fileGet(const std::string& path, std::string& data);
    static bool fileCopy(const std::string& src, const std::string& dst);
    static std::string fileExtension(const std::string& filepath, const bool& lowerExt = true);
    static std::string fileNameFromPath(const std::string& filepath);
    static std::string fileRemoveFileName(const std::string& filepath);
    static std::string fileRemoveExtension(const std::string& filepath);
    static void filePathRemoveProcessPath(std::string& path);
    static void filePathRemoveBasePath(const std::string& basePath, std::string& path);
    static bool fileWrite(const std::string& filepath, const Uint8* data, const Uint32& dataSize);
    static bool fileWrite(const std::string& filepath, const std::vector<Uint8>& data);
    static bool fileWrite(const std::string& filepath, const std::string& data);
    static bool fileRemove(const std::string& filepath);
    static bool fileHide(const std::string& filepath);
    static Uint32 fileGetModificationDate(const std::string& filepath);
    static bool fileCanWrite(const std::string& filepath);
    static bool fileIsHidden(const std::string& filepath);
    static void dirAddSlashAtEnd(std::string& path);
    static void dirRemoveSlashAtEnd(std::string& dir);
    static std::string removeLastFolderFromPath(std::string path);
    static std::vector<std::string> filesGetInPath(const std::string& path, const bool& sortByName = false, const bool& foldersFirst = false, const bool& ignoreHidden = false);
    static std::vector<String> filesGetInPath(const String& path, const bool& sortByName = false, const bool& foldersFirst = false, const bool& ignoreHidden = false);
    static std::vector<FileInfo> filesInfoGetInPath(std::string path, bool linkInfo = false, const bool& sortByName = false, const bool& foldersFirst = false, const bool& ignoreHidden = false);
    static Uint64 fileSize(const std::string& Filepath);
    static bool isDirectory(const std::string& path);
    static bool isDirectory(const String& path);
    static bool makeDir(const std::string& path, bool recursive = false, const Uint16& mode = 0770);
    static std::string getRealPath(const std::string& path);
    static std::string sizeToString(const Int64& Size);
    static bool changeWorkingDirectory(const std::string& path);
    static std::string getCurrentWorkingDirectory();
    static void filePathRemoveCurrentWorkingDirectory(std::string& path);
    static Int64 getDiskFreeSpace(const std::string& path);
    static std::string fileGetNumberedFileNameFromPath(std::string directoryPath, const std::string& fileName, const std::string& separator = ".", const std::string& fileExtension = "");
    static bool isRelativePath(const std::string& path);
    static FILE* fopenUtf8(const char* path, const char* mode);
    static FILE* fopenUtf8(const std::string& path, const std::string& mode);
};

Detailed Documentation

Methods

static std::string getOSSlash()

Returns:

The default slash path code of the current OS

static bool fileExists(const std::string& Filepath)

Returns:

True if the file exists ( false if is a directory, to know if directory exists use isDirectory )

static bool fileGet(const std::string& path, std::vector<Uint8>& data)

Copy a file to memory

Parameters:

path

The file path

data

The vector to allocate the file in memory

Returns:

True if returned the file to the vector.

static bool fileGet(const std::string& path, ScopedBuffer& data)

Copy a file to memory

Parameters:

path

The file path

data

A ScopedBuffer to allocate the data to memory

Returns:

True if returned the file to the ScopedBuffer

static bool fileGet(const std::string& path, std::string& data)

Copy a file to memory

Parameters:

path

The file path

data

The string to allocate the file in memory

Returns:

True if returned the file to the vector.

static bool fileCopy(const std::string& src, const std::string& dst)

Copy a file to location.

Parameters:

src

Source File Path

dst

Destination File Path

Returns:

If success.

static std::string fileExtension(const std::string& filepath, const bool& lowerExt = true)

Parameters:

filepath

The file path or name

lowerExt

Lowercase the extension obtained? ( true by default )

Returns:

The file extension

static std::string fileNameFromPath(const std::string& filepath)

Returns:

The file name of a file path

static std::string fileRemoveFileName(const std::string& filepath)

Returns:

Removes the file name from a path, and return the path.

static std::string fileRemoveExtension(const std::string& filepath)

Returns:

Removes the extension of a filepath

static void filePathRemoveProcessPath(std::string& path)

Removes the process path to a file path

static void filePathRemoveBasePath(const std::string& basePath, std::string& path)

Removes a base path from a file path

static bool fileWrite(const std::string& filepath, const Uint8* data, const Uint32& dataSize)

Write a file in binary mode and close it.

static bool fileWrite(const std::string& filepath, const std::vector<Uint8>& data)

Write a file in binary mode and close it.

static bool fileWrite(const std::string& filepath, const std::string& data)

Write a file in binary mode and close it.

static bool fileRemove(const std::string& filepath)

Deletes a file from the file system.

static bool fileHide(const std::string& filepath)

Hides the file in the file system

static Uint32 fileGetModificationDate(const std::string& filepath)

Returns:

The modification date of the file

static bool fileCanWrite(const std::string& filepath)

Returns:

If a file path is writeable

static bool fileIsHidden(const std::string& filepath)

Returns:

If the file is hidden (hidden attribute in Windows, files starting with ‘.’ in other systems

static void dirAddSlashAtEnd(std::string& path)

If the directory path not end with a slash, it will add it.

static void dirRemoveSlashAtEnd(std::string& dir)

If the directory path ends with a slash, it will remove it.

static std::string removeLastFolderFromPath(std::string path)

Move up from directory tree

static std::vector<std::string> filesGetInPath(const std::string& path, const bool& sortByName = false, const bool& foldersFirst = false, const bool& ignoreHidden = false)

Returns:

The files and sub directories contained by a directory

static std::vector<String> filesGetInPath(const String& path, const bool& sortByName = false, const bool& foldersFirst = false, const bool& ignoreHidden = false)

Returns:

The files and sub directories contained by a directory

static std::vector<FileInfo> filesInfoGetInPath(std::string path, bool linkInfo = false, const bool& sortByName = false, const bool& foldersFirst = false, const bool& ignoreHidden = false)

Returns:

The file info of the files and sub directories contained in the directory path.

static Uint64 fileSize(const std::string& Filepath)

Returns:

The size of a file

static bool isDirectory(const std::string& path)

Returns:

If directory exists, and is a directory

static bool isDirectory(const String& path)

Returns:

If directory exists, and is a directory

static bool makeDir(const std::string& path, bool recursive = false, const Uint16& mode = 0770)

Creates a new directory

static std::string getRealPath(const std::string& path)

Returns:

The absolute path of a relative path

static std::string sizeToString(const Int64& Size)

Convert a size represented in bytes, to a string converted in byes/kb/mb/tb. For example 10485760 -> “10.0 MB”

static bool changeWorkingDirectory(const std::string& path)

Change the process current working directory

static std::string getCurrentWorkingDirectory()

Gets the current working directory

static void filePathRemoveCurrentWorkingDirectory(std::string& path)

Removes the current working directory from a path

static Int64 getDiskFreeSpace(const std::string& path)

Returns:

Returns free disk space for a given path in bytes

static std::string fileGetNumberedFileNameFromPath(std::string directoryPath, const std::string& fileName, const std::string& separator = ".", const std::string& fileExtension = "")

Creates a file name available for the directory path. For file name “file-name-” will search the first available name in the file system starting from file-name-1, file-name-2, and so on.

Returns:

The file name found, otherwise empty string if error.

static bool isRelativePath(const std::string& path)

Returns:

True if the path provided is relative.

static FILE* fopenUtf8(const char* path, const char* mode)

Opens a file path with a path and mode encoded in UTF-8

static FILE* fopenUtf8(const std::string& path, const std::string& mode)

Opens a file path with a path and mode encoded in UTF-8