This class provides functionality for working with files.
#include <utility/YiFile.h>
Static Public Member Functions | |
static CYIString | ExtractFilenameFromPath (const CYIString &rPath) |
static CYIString | ExtractParentFromPath (const CYIString &rPath) |
static CYIString | GetNormalizedPath (const CYIString &path) |
static CYIString | Join (const CYIString &pathPrefix, const CYIString &pathSuffix) |
static bool | IsFile (const CYIString &rPath) |
static uint64_t | GetSize (const CYIString &rPath, bool *pError=nullptr) |
static CYIDateTime | GetLastModificationDate (const CYIString &rPath, bool *pError=nullptr) |
static uint64_t | GetModeAndType (const CYIString &rPath, bool *pError=nullptr) |
static CYIString | GetBytesAsString (uint64_t bytes) |
static CYIString | ReadAsString (const CYIString &path, bool *pError=nullptr, bool logErrors=true) |
static std::vector< uint8_t > | ReadAsVector (const CYIString &path, bool *pError=nullptr, bool logErrors=true) |
Parses the filename from the supplied path. The rPath provided can be absolute or relative. This function will return the name found after the last separator found in rPath. This function will return a empty string in the event that a name cannot be found, or if the path could not be parsed. This function will return the original path if the path does not contain the directory separator character.
Parses the containing directory's path from the supplied path. The rPath provided can be absolute or relative. This function will return the path found before the last separator found in rPath. This function will return a empty string in the event that a directory cannot be found, or if the path could not be parsed. The returned string may end with the directory separator character.
|
static |
Formats the number of bytes bytes as a string. Returned values are formatted with the appropriate suffix. For example, calling this function with 2048 will return '2.0 kB', and calling this function with 2354 will return '2.3 kB'.
|
static |
Returns the last modification date of the file rPath.
Returns a CYIDateTime object initialized with an epoch time of 0 if the file doesn't exist or if its modification date cannot be read, and sets *pError to false if pError is non-null.
|
static |
Returns the mode and type of the file rPath.
Returns 0 if the file doesn't exist or if its mode cannot be read, and sets *pError to false if pError is non-null.
Returns a path with the /. path sections, the /.. path sections and empty path sections removed. Removed /.. path sections result in the 'parent' path section also being removed.
Examples:
/path/to/my/file -> /path/to/my/file /path/to/my//file -> /path/to/my/file /path/to/my/../file -> /path/to/file /path/to/my/../../file -> /path/file /path/to/my/../.. -> /path path/to/./file -> path/to/file ./path/to/./file -> ./path/to/file /path/../to/path/ -> /to/path/ path/../to/path/ -> to/path/ ../errorCase/to/../file -> ../errorCase/file
|
static |
Returns the size of the file rPath.
Returns 0 if the file doesn't exist or if its size cannot be read, and sets *pError to false if pError is non-null.
pError
being set to true)
|
static |
Returns true if the file located at rPath exists.
|
static |
Joins two sections of path together, adding platform-specific separators as needed. For example, calling this function on an unix platform with with 'folder1/folder2' and 'folder3/file.txt' will result in the path 'folder1/folder2/folder3/file.txt' being returned.
|
static |
Reads the content of the file path into a CYIString.
If pError is provided, its pointed-to boolean will be set to true if an error occurred reading the file, and false otherwise. If an error occured and logErrors is true, then the error will be written to the log. If an error is encountered when reading the file, an empty vector is returned.
|
static |
Reads the content of the file path into a vector.
If pError is provided, its pointed-to boolean will be set to true if an error occurred reading the file, and false otherwise. If an error occured and logErrors is true, then the error will be written to the log. If an error is encountered when reading the file, an empty vector is returned.