class FileSystem

Static class containing file system utility functions.

Public Static Functions

static Str fromNativeSeparators(const Str &path)

Converts path from using native separators to always use ‘/’ as separator.

static Str toNativeSeparators(const Str &path)

Returns path with separators that are appropriate for the underlying operating system.

static Str addTrailingSeparator(const Str &path)

Adds a trailing separator to the input path if one isn’t already present.

static Str removeTrailingSeparator(const Str &path)

Returns path with any trailing separators removed.

static Str fileName(const Str &path)

Returns the file name component of the path.

The returned file name will include the file extension

static Str extension(const Str &path)

Returns the file extension, including the leading ‘.’.

static Str parentPath(const Str &path)

Returns the parent path of the specified input path.

static Str makeAbsolute(const Str &path)

Convert a relative path to an absolute path.

static Str currentPath()

Returns the full path of the current working directory.

static bool pathExists(const Str &pathName)

Checks whether the specified file or directory exists.

static bool fileExists(const Str &fileName)

Returns true if the specified file exists.

static bool directoryExists(const Str &dirName)

Returns true if the specified directory exists.

static bool createDirectory(const Str &dirName)

Creates a directory.

Creates only one new directory per call, so only the last component of dirName can name a new directory.

If the directory already exists when this function is called, it will return false.

static bool createDirectoryTree(const Str &dirPath)

Creates the directory path dirPath.

The function will try to create all parent directories necessary to create the directory.

Returns true if successful or if the path already exists, otherwise returns false.

static bool copyFile(const Str &fromFileName, const Str &toFileName)

Copies a file.

static bool deleteFile(const Str &fileName)

Deletes a file.

static bool deleteDirectory(const Str &dirName)

Deletes an empty directory.

The directory must be empty, and it must not be the current working directory or the root directory.

static bool deleteAllFilesInDirectory(const Str &dirName)

Deletes all files within the specified directory.

static bool deleteDirectoryRecursive(const Str &dirName)

Deletes a directory and all its contents recursively.

static bool getDirectoryContents(const Str &dirName, std::vector<Str> *fileNameArr, std::vector<Str> *dirNameArr)

Gets all files and sub-directories in the specified directory.

static std::vector<Str> getAllFilesInDirectory(const Str &dirName)

Gets all files in the specified directory.

static std::vector<Str> findFilesInDirectory(const Str &dirName, const Str &filePattern)

Returns all files matching filePattern in the specified directory.

static uint64_t fileSize(const Str &fileName)

Returns the size of the given file in bytes.

static unsigned int fileContentsCrc(const Str &fileName, uint64_t maxBytesToRead)

Returns the computed CRC of the contents of the given file.

If maxBytesToRead > 0, only the first maxBytesToRead bytes of the file will be used.