You.i Engine
CYIFile Class Reference

Detailed Description

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)
 

Member Function Documentation

◆ ExtractFilenameFromPath()

static CYIString CYIFile::ExtractFilenameFromPath ( const CYIString rPath)
static

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.

◆ ExtractParentFromPath()

static CYIString CYIFile::ExtractParentFromPath ( const CYIString rPath)
static

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.

◆ GetBytesAsString()

static CYIString CYIFile::GetBytesAsString ( uint64_t  bytes)
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'.

◆ GetLastModificationDate()

static CYIDateTime CYIFile::GetLastModificationDate ( const CYIString rPath,
bool *  pError = nullptr 
)
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.

◆ GetModeAndType()

static uint64_t CYIFile::GetModeAndType ( const CYIString rPath,
bool *  pError = nullptr 
)
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.

Note
The format of the mode and type is platform-dependant. Some platforms do not support reading the mode and type, and will return 0.

◆ GetNormalizedPath()

static CYIString CYIFile::GetNormalizedPath ( const CYIString path)
static

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.

Note
Only '/' is suported as path separator.

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

◆ GetSize()

static uint64_t CYIFile::GetSize ( const CYIString rPath,
bool *  pError = nullptr 
)
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.

Note
The reported size for directories is platform-specific (and querying that size may result in pError being set to true)

◆ IsFile()

static bool CYIFile::IsFile ( const CYIString rPath)
static

Returns true if the file located at rPath exists.

Note
This function does not differentiate between file types. This function will return true if the file at rPath is a directory.
See also
CYIDir::IsDirectory

◆ Join()

static CYIString CYIFile::Join ( const CYIString pathPrefix,
const CYIString pathSuffix 
)
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.

◆ ReadAsString()

static CYIString CYIFile::ReadAsString ( const CYIString path,
bool *  pError = nullptr,
bool  logErrors = true 
)
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.

Note
If the file contains 'null' characters, then calling CYIString::GetData() on the string would appear to only return a portion of the file. Furthermore, if the file doesn't contain UTF-8-encoded data, then some of the CYIString functions may behave incorrectly. The raw data of the file can be accessed using CYIString::GetData(), and the number of bytes in the array (e.g. the file size) can be accessed using CYIString::GetSizeInBytes().
See also
ReadAsVector

◆ ReadAsVector()

static std::vector<uint8_t> CYIFile::ReadAsVector ( const CYIString path,
bool *  pError = nullptr,
bool  logErrors = true 
)
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.

See also
ReadAsString

The documentation for this class was generated from the following file: