NDEVR
API Documentation

Logic for reading or writing to a file as well as navigating filesystems or other common file operations. More...

Inheritance diagram for File:
[legend]
Collaboration diagram for File:
[legend]

Public Types

enum  FilePart {
  e_drive = 0x01 , e_dir_path = 0x02 , e_file_name = 0x04 , e_file_extension = 0x08 ,
  e_full_path = e_drive | e_dir_path | e_file_name | e_file_extension
}
 Bitmask flags representing parts of a file path. More...
enum  OpenMode : uint01 {
  e_binary_read , e_binary_write , e_ascii_read , e_ascii_write ,
  e_ascii_read_safe , e_binary_read_safe , e_ascii_write_safe , e_binary_write_safe ,
  e_undefined
}
 Specifies the mode in which a file is opened. More...

Public Member Functions

 File ()
 Default constructor.
 File (const File &file)
 Copy constructor.
 File (const String &full_path)
 Constructs a File from a full path string.
 File (const String &resource_name, const String &path_id)
 Constructs a File from a resource name and path identifier.
 File (const StringView &full_path)
 Constructs a File from a StringView of a full path.
 File (File &&file) noexcept
 Move constructor.
 File (String &&full_path)
 Constructs a File by moving a path string.
 ~File ()
 Destructor.
Fileappend (const char &s)
 Appends a single character to the file path.
Fileappend (const StringView &s)
 Appends a string to the file path.
FileappendPath (const char *cs)
 Appends a path component to this file path.
FileappendPath (const String &cs)
 Appends a path component to this file path.
FileappendPath (const StringView &cs)
 Appends a path component to this file path.
uint08 availableDiskSpace (bool privelaged=true) const
 Queries the available disk space on the drive containing this file.
bool cachedExist () const
 Checks whether the file exists using cached data rather than querying the filesystem.
void close ()
 Closes the file if it is open.
bool copyTo (const File &cs, bool override_file, LogPtr log=LogPtr()) const
 Copies this file to a destination.
void create (bool override_file) const
 Creates the file or directory on disk.
const FileCachedDatacurrentCache () const
 Returns the current cached file metadata.
void deleteFile (LogPtr log=LogPtr())
 Deletes this file from disk.
bool exists () const
 Checks whether this file or directory exists on disk.
void expandEnvironmentalVars ()
 Expands any environment variables present in the file path.
FILE * filePtr () const
 Returns the underlying C FILE pointer for this file.
uint08 fileSize () const
 Gets the size of the file in bytes.
File findNonExistingSuitableName () const
 Generates a unique file name based on this path that does not conflict with existing files.
void flush ()
 Flushes any buffered data to disk.
File generateTempFile () const
 Generates a temporary file path derived from this file's directory.
Time getAccessTime () const
 Gets the last access time of the file.
FileBuffer getChildren () const
 Retrieves all direct children of this directory.
FileBuffer getChildrenMatching (const Buffer< String > &include_patterns, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
 Retrieves children of this directory matching any of the given patterns.
FileBuffer getChildrenMatching (const Buffer< String > &include_patterns, const Buffer< String > &exclude_patterns, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
 Retrieves children matching include patterns while excluding others.
FileBuffer getChildrenMatching (const Buffer< StringView > &include_patterns, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
 Retrieves children of this directory matching any of the given StringView patterns.
FileBuffer getChildrenMatching (const Buffer< StringView > &include_patterns, const Buffer< StringView > &exclude_patterns, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
 Retrieves children matching include patterns while excluding others, using StringView patterns.
FileBuffer getChildrenMatching (const StringView &include_pattern, bool recursive=false, uint04 max_count=Constant< uint04 >::Max) const
 Retrieves children of this directory matching a pattern.
Time getCreationTime () const
 Gets the creation time of the file.
Buffer< uint01getData ()
 Reads the entire file contents into a byte buffer.
HighCapacityBuffer< uint01getDataExtended ()
 Reads the entire file contents into a high-capacity byte buffer for large files.
String getDriveDescription () const
 Retrieves a human-readable description of the drive this file resides on.
void getFileTimes (Time &modified_time, Time &creation_time, Time &access_time) const
 Retrieves all three file timestamps at once.
StringView getFolderName (bool trailing_mark=false) const
 Retrieves the folder name portion of the file path.
Time getModifiedTime () const
 Gets the last modified time of the file.
File getParentDirectory () const
 Gets the parent directory of this file.
StringView getPath (uint01 file_parts) const
 Retrieves a subset of the file path based on the specified parts.
UUID getUUID () const
 Gets a UUID that uniquely identifies this file on the filesystem.
bool hasNullBytes (uint08 max_length=Constant< uint08 >::Max)
 Checks whether the file contains null bytes within the specified range.
void invalidateCache ()
 Invalidates the cached file metadata, forcing a refresh on next access.
bool isDirectory () const
 Checks whether this path refers to a directory.
bool isDrive () const
 Checks whether this path refers to a drive root.
bool isHidden () const
 Checks whether this file is hidden.
bool isMTP () const
 Checks whether this file path refers to an MTP (Media Transfer Protocol) device.
bool isOpen () const
 Checks whether this file is currently open.
void makeReadOnly (bool read_only)
 Sets or clears the read-only attribute on this file.
bool moveTo (File &file, bool override_file, LogPtr log=LogPtr(), bool is_source_temp=false)
 Moves this file to a new location.
FILE * open (OpenMode mode, bool append=false)
 Opens the file with the specified mode.
size_t operator() () const
 Functor operator for use as a hash key in standard containers.
bool operator<< (const Buffer< uint01 > &values)
 Writes a byte buffer to the file.
bool operator<< (const fltp04 &value)
 Writes a 32-bit floating-point value to the file.
bool operator<< (const fltp08 &value)
 Writes a 64-bit floating-point value to the file.
bool operator<< (const HighCapacityBuffer< uint01 > &values)
 Writes a high-capacity byte buffer to the file.
bool operator<< (const StringView &value)
 Writes a string to the file.
Fileoperator= (const File &value)
 Copy assignment operator.
Fileoperator= (File &&value) noexcept
 Move assignment operator.
Fileoperator= (String &value)
 Assignment operator from a String reference.
bool parentDirectoryExists () const
 Checks whether the parent directory of this file exists.
const StringpathID () const
 Gets the path identifier string for this file.
StringView pathNameID () const
 Gets a combined path and name identifier for this file.
String relativePathTo (const File &reference) const
 Computes the relative path from this file to a reference file.
void removeInvalidChars ()
 Removes characters from the path that are invalid for the current filesystem.
void removeOpenOwnership ()
 Releases ownership of the open file handle without closing it.
bool resolveMTPPath () const
 Resolves the actual filesystem path from an MTP device path.
bool resolveNameFromMTPPath ()
 Resolves the display name from an MTP device path.
void setFolderName (const StringView &folder_name)
 Sets the folder name portion of the file path.
void setFromDisplayString (const StringView &display_string)
 Sets this file path from a user-friendly display string.
void setInternalVars ()
 Recalculates internal cached path component indices from the current path string.
void setPath (const StringView &path, uint01 part)
 Sets a specific part of the file path.
void throwIfNotExist () const
 Throws an exception if this file does not exist.
String toDisplayString ()
 Converts this file path to a user-friendly display string.
bool updateAccessedTime () const
 Updates the last accessed time of the file to the current time.
bool updateAccessedTime (Time access_time) const
 Updates the last accessed time of the file to a specific time.
void updateCache () const
 Updates the cached file metadata from the filesystem.
void updateCache (const FileCachedData &cache)
 Updates the cached file metadata with the provided data.
Public Member Functions inherited from String
constexpr String () noexcept
 Constructor used to create an empty String*.
constexpr String (const char *const string, uint04 size)
 String Constructor char arrays when the size is known.
 String (const char *string)
 String Constructor for null terminated array of chars.
template<std::size_t N>
constexpr String (const char(&string)[N])
 String Constructor for static char arrays.
constexpr String (const String &string)
 Copy Constructor.
constexpr String (const StringView &string)
 Constructor for string view.
template<class t_type>
 String (const t_type &value)
 String Constructor that creates a string based off an object.
template<std::size_t N>
 String (const wchar(&string)[N])
 String Constructor for static wchar arrays of UTF16 data.
constexpr String (String &&string) noexcept
 Move contructor (No new memory allocation).
constexpr String (uint04 size, const char &value)
 String Constructor creates a string of a size and fills it with a character.
void addUTF16AsUTF8 (const wchar *unicode)
 Converts a unicode null terminated string of UTF16 wchars into UTF8 and appends it to the end of the String.
bool addUTF16CharAsUTF8 (const wchar *unicode, uint04 &advance)
 Converts a single unicode character at advance into UTF8 and appends it to the end of the String.
void addWChar (const wchar &object)
 Converts a single unicode character UTF16 character into one or more UTF8 characters and appends them to the end of this String.
StringaddWhiteSpace (uint04 desired_string_size, uint04 desired_right_alignment_location=0, char whitespace=' ')
 Used for formatting, will, if necessary, add white space so that the string becomes a certain length.
Stringappend (char value)
 Appends an object to the back of this string.
Stringappend (const char *value)
 Appends a string to the back of this string.
template<size_t t_size>
Stringappend (const char(&value)[t_size])
 Appends a string to the back of this string.
Stringappend (const StringView &string)
 Appends a string to the back of this string.
template<class t_type>
Stringappend (const t_type &value)
 Appends a string to the back of this string.
Stringappend (const wchar *value)
 Appends a string to the back of this string.
Stringappend (const wchar value)
 Appends a wchar utf16 to the back of this string as utf8.
template<size_t t_size>
Stringappend (const wchar(&value)[t_size])
 Appends a string to the back of this string.
bool beginsWith (const StringView &s, bool ignore_case=false) const
 Tests if this String starts with the specified prefix.
constexpr const char * c_str () const
 Used to access the raw memory of this string.
bool endsWith (const StringView &s, bool ignore_case=false) const
 Tests if this String ends with the specified suffix.
StringformatNumberString (bool add_comma, uint04 decimals)
 For a string representing a number, makes the decimals equal to the the provided value and adds comma seperators if number is large enough.
StringformatNumberString (bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, char decimal='.', char comma=',')
 Modifies the contents of this string, that represents a given number using the provided rules.
StringformatNumberString (uint04 decimals)
 For a string representing a number, makes the decimals equal to the the provided value Example: String("1000000").formatNumberString(2); will make "1000000.00".
uint04 fromHex () const
 Converts a hex value into an unsigned 4 byte number.
template<class t_type>
decltype(autogetAs () const
 Converts a string into an object.
constexpr uint08 hash () const
 Creates a simple, quick hash of the object.
uint08 hashLower () const
 Creates a simple, quick hash of the object.
uint08 hashUpper () const
 Creates a simple, quick hash of the object.
bool hasSubString (const StringView &sub_string, bool ignore_case=false, uint04 start_idx=0) const
 Tests if this String contains the specified substring.
uint04 indexOf (const char &sub_string) const
 Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf (const char &sub_string, uint04 start_pos) const
 Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf (const char &sub_string, uint04 start_pos, uint04 size) const
 Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf (const char *sub_string, bool ignore_case, uint04 start_index, uint04 size) const
 Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf (const char *sub_string, bool ignore_case=false, uint04 start_index=0) const
 Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf (const char *sub_string, char escape_char, bool ignore_case=false, uint04 start_index=0) const
 Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf (const String &sub_string, bool ignore_case=false, uint04 start_index=0) const
 Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf (const StringView &sub_string, bool ignore_case=false, uint04 start_index=0) const
 Given a substring specified by the input, returns the first index of that string, if it exists.
String insertNewLines (uint04 max_line_size) const
 Finds key areas to insert new lines such that the rows are at most, the length provided.
bool isNumeric () const
 Checks to see if the string is a numeric string.
bool isSameNoCase (const StringView &s) const
 Checks whether two strings match in a case-insensitive way.
uint04 lastIndexOf (const char *sub_string, bool ignore_case=false) const
 Given a substring specified by the input, returns the last index of that string, if it exists.
uint04 lastIndexOf (const char value, bool ignore_case=false) const
 Given a value specified by the input, returns the last index of that char, if it exists.
uint04 lastIndexOf (const StringView &sub_string, bool ignore_case=false) const
 Given a substring specified by the input, returns the last index of that string, if it exists.
bool matchesWildcard (const StringView &pattern) const
 Checks whether two strings match allowing '' to be used as a wildcard pattern.
String predictNextStringIncrement () const
 Looks in the string for key markers that might be an index, and attempts to increment the index.
StringremoveNonAlphaNumeric (bool remove_tab=true, bool remove_space=true, bool remove_new_line=true, bool remove_r=true, bool remove_numbers=false)
 Removes any characters that aren't numbers or letters with other options available.
StringremoveNonNumeric ()
 Removes anything that is not a number or decimal ('0'-'9' or .).
Stringreplace (const StringView &sub_string, const StringView &replace_sub_string, bool ignore_case=false, uint04 start_index=0)
 Replaces ALL instances of a given substring with the provided replacement.
Stringreplace (const StringViewBuffer &sub_string, const StringBuffer &replace_sub_string, bool ignore_case=false, uint04 start_index=0)
 Replaces ALL instances of the given substrings with the provided replacements.
Stringreplace (const StringViewBuffer &sub_string, const StringViewBuffer &replace_sub_string, bool ignore_case=false, uint04 start_index=0)
 Replaces ALL instances of the given substrings with the provided replacements.
StringAllocatingView shortenString (uint04 size) const
 Shortens the string to the max size provided.
StringViewBuffer split (char delimiter, bool preserve_empty=true) const
 Given a delimiter, breaks the string into subsections, returning an array of each subsection.
StringViewBuffer split (const Buffer< char > &delimiter, bool preserve_empty=true) const
 Given multiple delimiter, breaks the string into subsections, returning an array of each subsection.
void splitString (char delimiter, StringViewBuffer &strings, bool preserve_empty=true) const
 Given multiple delimiter, breaks the string into subsections, and APPENDS each substring to the given Buffer.
void splitString (const Buffer< char > &delimiter, StringViewBuffer &strings, bool preserve_empty=true) const
 Given multiple delimiter, breaks the string into subsections, and APPENDS each substring to the given Buffer.
StringView substr (uint04 start) const
 Creates a substring from a given start position, to the end of the string.
StringView substr (uint04 start, uint04 end) const
 Creates a substring from a given start position, to the given end position, non-inclusive of the end index.
StringAllocatingView toLower () const
 changes all upper case characters into lower case characters.
String toTitleString () const
 Formats the string to be a title, capitalizing important characters and replacing underscores with spaces.
StringAllocatingView toUpper () const
 changes all lower case characters into upper case characters.
StringtrimWhiteSpace ()
 Trims any white space (tabs, spaces, etc) from the beginning and end of the string.
Public Member Functions inherited from Buffer< char, BufferAllocator< char, 0, true, uint04, true > >
constexpr Buffer () noexcept
 Creates an empty buffer.
 ~Buffer ()
void add (char &&object)
 Adds object to the end of the buffer.
void addSpace (t_index_type space_to_add)
 Adds a space to the end of the buffer.
operator decltype auto () const
 Gets the first location of type* in the array.
sint04 compare (const Buffer &value) const
 Compares this Buffer to another to determine their relative ordering.
Buffer< t_other_type, t_other_memory_manager > getAs () const
 Gets a copy of this buffer, with filled objects t_other_type, where all objects are created using the contents of this buffer.
void insert (t_index_type location, const char &object)
 Adds an object to a specific location.
void removeAllOrdered (const char &object)
 Removes all instances of the object.
void removeAllOrderedFn (const t_functor &functor)
 Removes all items based on the functor.
void removeAllUnordered (const char &object)
 Removes all unordered described by object.

Static Public Member Functions

static bool accessSort (const File &i, const File &j)
 Comparison function for sorting files by last access time.
static bool createSort (const File &i, const File &j)
 Comparison function for sorting files by creation time.
static bool DoesFileExist (const String &name)
 Checks whether a file with the given name exists.
static String FileSizeToString (uint08 file_size)
 Converts a file size in bytes to a human-readable string (e.g., "1.5 MB").
static bool isIDSep (const char &path)
 Checks whether a character is an ID separator.
static bool isPathSep (const char &path)
 Checks whether a character is a path separator.
static FileBuffer MTPDevices ()
 Retrieves all connected MTP (Media Transfer Protocol) devices.
static bool nameSort (const File &i, const File &j)
 Comparison function for sorting files by name.
static FileBuffer SystemDrives ()
 Retrieves all system drives.
static File TempFileFolder ()
 Gets the system temporary file folder.
static bool typeSort (const File &i, const File &j)
 Comparison function for sorting files by type (extension).
Static Public Member Functions inherited from String
static bool AlphaNumericCompare (const StringView &left, const StringView &right)
 Compares two strings given their alpha-numeric determined value.
template<class t_type>
static TranslatedString DisplayString (const t_type &value)
 Converts an object into a TranslatedString.
static constexpr uint08 hash (const char *value)
 constexpr method to hash a value.
static bool IsNumeric (char value)
 Checks to see if the char is a numeric string.
static bool IsWhiteSpace (char s)
 Checks whether a given character is a whitespace character or not.
static String NumberString (fltp08 value, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, char decimal='.', char comma=',')
 Creates a string from a given number using the provided rules.
static constexpr uint04 str_len (const char *value)
 constexpr method to get the length of a null-terminated string at compile time
static constexpr uint04 str_len (const wchar *value)
 constexpr method to get the UTF8 length of a null-terminated string at compile time
static String ToAlphaString (uint04 number)
 Converts a number into a char string.
static String ToHex (char value)
 Converts the memory of the given object into a hexidecimal string.
template<class t_object, class t_allocator>
static String ToHex (const Buffer< t_object, t_allocator > &values)
 Converts a buffer of objects into a hexidecimal string.
static String ToHex (const StringView &values)
 Converts a string of any type of data (assumed to be binary) into a hex representation.
template<uint01 t_size, class t_type>
static String ToHex (const Vector< t_size, t_type > &values)
 Converts a vector into a hex representation.
template<class t_object>
static std::enable_if< ObjectInfo< t_object >::Integer, String >::type ToHex (t_object value)
 Converts the memory of the given object into a hexidecimal string.
static String ToHex (uint01 value)
 Converts the memory of the given object into a hexidecimal string.
static constexpr Vector< 2, char > ToHexVec (char value)
 Converts the memory of the given object into a hexidecimal string.
static constexpr Vector< 2, char > ToHexVec (uint01 value)
 Converts the memory of the given object into a hexidecimal string.
static String UTF16toUTF8 (const wchar *unicode, uint04 &advance)
 Converts a single unicode character at advance into UTF8 and and returns it as a String.
static wchar UTF8toUTF16 (const char *utf8, uint04 &advance)
 Converts a unicode null terminated string of chars into a UTF16 wchar and increments advance by the ammount of characters consumed to make the UTF16 character.

Static Public Attributes

static constexpr char DriveSep = ':'
 Drive separator character (e.g., "C:").
static constexpr char ExtSep = '.'
 File extension separator character.
static constexpr char IDSep = '|'
 ID separator character used in path identifiers.
static constexpr char PathSep = '/'
 Platform-specific path separator character.
static constexpr StringView PathSepS = "/"
 Platform-specific path separator string.

Protected Attributes

FileCachedData m_cached_data
 Cached file metadata such as size, times, and existence.
uint01 m_file_ext_start
 Index into the path string where the file extension begins.
uint01 m_file_name_start
 Index into the path string where the file name begins.
FILE * m_file_ptr
 The underlying C file pointer, or nullptr if not open.
String m_id
 The path identifier string for this file.
bool m_id_valid
 Whether the cached path identifier is currently valid.
OpenMode m_open_mode
 The current open mode of the file.
uint01 m_path_start
 Index into the path string where the directory path begins.

Detailed Description

Logic for reading or writing to a file as well as navigating filesystems or other common file operations.


See also
BinaryFile, FileResource, FileFormat, FileOptions

Definition at line 52 of file File.h.

Member Enumeration Documentation

◆ FilePart

Bitmask flags representing parts of a file path.

Enumerator
e_drive 

The drive component of the path (e.g., "C:").

e_dir_path 

The directory component of the path.

e_file_name 

The file name without extension.

e_file_extension 

The file extension (e.g., ".txt").

e_full_path 

The complete file path including all components.

Definition at line 73 of file File.h.

◆ OpenMode

Specifies the mode in which a file is opened.

Enumerator
e_binary_read 

Open for binary reading.

e_binary_write 

Open for binary writing.

e_ascii_read 

Open for ASCII text reading.

e_ascii_write 

Open for ASCII text writing.

e_ascii_read_safe 

Open for ASCII text reading with safety checks.

e_binary_read_safe 

Open for binary reading with safety checks.

e_ascii_write_safe 

Open for ASCII text writing with safety checks.

e_binary_write_safe 

Open for binary writing with safety checks.

e_undefined 

Undefined or unset open mode.

Definition at line 58 of file File.h.

Constructor & Destructor Documentation

◆ File() [1/7]

◆ File() [2/7]

File::File ( const File & file)

Copy constructor.

Parameters
[in]fileThe File to copy from.

References File().

◆ File() [3/7]

File::File ( const String & resource_name,
const String & path_id )

Constructs a File from a resource name and path identifier.

Parameters
[in]resource_nameThe name of the resource.
[in]path_idThe path identifier for the resource.

References String::String().

◆ File() [4/7]

File::File ( File && file)
noexcept

Move constructor.

Parameters
[in]fileThe File to move from.

References File().

◆ File() [5/7]

File::File ( const String & full_path)
explicit

Constructs a File from a full path string.

Parameters
[in]full_pathThe complete file path.

References String::String().

◆ File() [6/7]

File::File ( const StringView & full_path)

Constructs a File from a StringView of a full path.

Parameters
[in]full_pathThe complete file path as a StringView.

◆ File() [7/7]

File::File ( String && full_path)
explicit

Constructs a File by moving a path string.

Parameters
[in]full_pathThe complete file path to move from.

References String::String().

◆ ~File()

File::~File ( )

Destructor.

Closes the file if open.

Member Function Documentation

◆ accessSort()

bool File::accessSort ( const File & i,
const File & j )
staticnodiscard

Comparison function for sorting files by last access time.

Parameters
[in]iThe first file to compare.
[in]jThe second file to compare.
Returns
True if i should come before j when sorted by access time.

References File().

◆ append() [1/2]

File & File::append ( const char & s)

Appends a single character to the file path.

Parameters
[in]sThe character to append.
Returns
A reference to this File.

References File().

◆ append() [2/2]

File & File::append ( const StringView & s)

Appends a string to the file path.

Parameters
[in]sThe string to append.
Returns
A reference to this File.

References File().

Referenced by open().

◆ appendPath() [1/3]

File & File::appendPath ( const char * cs)

Appends a path component to this file path.

Parameters
[in]csThe path component to append as a C-string.
Returns
A reference to this File.

References File().

◆ appendPath() [2/3]

File & File::appendPath ( const String & cs)

Appends a path component to this file path.

Parameters
[in]csThe path component to append.
Returns
A reference to this File.

References File(), and String::String().

◆ appendPath() [3/3]

File & File::appendPath ( const StringView & cs)

Appends a path component to this file path.

Parameters
[in]csThe path component to append.
Returns
A reference to this File.

References File().

Referenced by ShaderTools::compileShader().

◆ availableDiskSpace()

uint08 File::availableDiskSpace ( bool privelaged = true) const

Queries the available disk space on the drive containing this file.

Parameters
[in]privelagedWhether to query privileged (total available) space.
Returns
The available disk space in bytes.

◆ cachedExist()

bool File::cachedExist ( ) const
nodiscard

Checks whether the file exists using cached data rather than querying the filesystem.

Returns
True if the cached data indicates the file exists.

◆ copyTo()

bool File::copyTo ( const File & cs,
bool override_file,
LogPtr log = LogPtr() ) const

Copies this file to a destination.

Parameters
[in]csThe destination file.
[in]override_fileWhether to overwrite the destination if it exists.
[in]logOptional log for reporting progress or errors.
Returns
True if the copy succeeded.

References File().

◆ create()

void File::create ( bool override_file) const

Creates the file or directory on disk.

Parameters
[in]override_fileWhether to overwrite the file if it already exists.

◆ createSort()

bool File::createSort ( const File & i,
const File & j )
staticnodiscard

Comparison function for sorting files by creation time.

Parameters
[in]iThe first file to compare.
[in]jThe second file to compare.
Returns
True if i should come before j when sorted by creation time.

References File().

◆ currentCache()

const FileCachedData & File::currentCache ( ) const

Returns the current cached file metadata.

Returns
A const reference to the cached data.

◆ deleteFile()

void File::deleteFile ( LogPtr log = LogPtr())

Deletes this file from disk.

Parameters
[in]logOptional log for reporting progress or errors.

◆ DoesFileExist()

bool File::DoesFileExist ( const String & name)
staticnodiscard

Checks whether a file with the given name exists.

Parameters
[in]nameThe file path to check.
Returns
True if the file exists.

References String::String().

◆ exists()

bool File::exists ( ) const
nodiscard

Checks whether this file or directory exists on disk.

Returns
True if the file or directory exists.

Referenced by GoogleEarthApplicationManager::hasActiveInstallation(), and TranslationTools::makeTranslation().

◆ filePtr()

FILE * File::filePtr ( ) const
nodiscard

Returns the underlying C FILE pointer for this file.

Returns
The FILE pointer, or nullptr if the file is not open.

◆ fileSize()

uint08 File::fileSize ( ) const
nodiscard

Gets the size of the file in bytes.

Returns
The file size in bytes.

◆ FileSizeToString()

String File::FileSizeToString ( uint08 file_size)
staticnodiscard

Converts a file size in bytes to a human-readable string (e.g., "1.5 MB").

Parameters
[in]file_sizeThe file size in bytes.
Returns
A formatted string representing the file size.

References String::String().

◆ findNonExistingSuitableName()

File File::findNonExistingSuitableName ( ) const

Generates a unique file name based on this path that does not conflict with existing files.

Returns
A File with a non-existing, suitable name derived from this path.

References File().

◆ generateTempFile()

File File::generateTempFile ( ) const
nodiscard

Generates a temporary file path derived from this file's directory.

Returns
A File representing the generated temporary file path.

References File().

◆ getAccessTime()

Time File::getAccessTime ( ) const
nodiscard

Gets the last access time of the file.

Returns
The access Time.

◆ getChildren()

FileBuffer File::getChildren ( ) const
nodiscard

Retrieves all direct children of this directory.

Returns
A FileBuffer containing the child files and directories.

◆ getChildrenMatching() [1/5]

FileBuffer File::getChildrenMatching ( const Buffer< String > & include_patterns,
bool recursive = false,
uint04 max_count = Constantuint04 >::Max ) const
nodiscard

Retrieves children of this directory matching any of the given patterns.

Parameters
[in]include_patternsThe patterns to match against.
[in]recursiveWhether to search subdirectories recursively.
[in]max_countThe maximum number of results to return.
Returns
A FileBuffer containing the matching children.

◆ getChildrenMatching() [2/5]

FileBuffer File::getChildrenMatching ( const Buffer< String > & include_patterns,
const Buffer< String > & exclude_patterns,
bool recursive = false,
uint04 max_count = Constantuint04 >::Max ) const
nodiscard

Retrieves children matching include patterns while excluding others.

Parameters
[in]include_patternsThe patterns to include.
[in]exclude_patternsThe patterns to exclude.
[in]recursiveWhether to search subdirectories recursively.
[in]max_countThe maximum number of results to return.
Returns
A FileBuffer containing the matching children.

◆ getChildrenMatching() [3/5]

FileBuffer File::getChildrenMatching ( const Buffer< StringView > & include_patterns,
bool recursive = false,
uint04 max_count = Constantuint04 >::Max ) const
nodiscard

Retrieves children of this directory matching any of the given StringView patterns.

Parameters
[in]include_patternsThe patterns to match against.
[in]recursiveWhether to search subdirectories recursively.
[in]max_countThe maximum number of results to return.
Returns
A FileBuffer containing the matching children.

◆ getChildrenMatching() [4/5]

FileBuffer File::getChildrenMatching ( const Buffer< StringView > & include_patterns,
const Buffer< StringView > & exclude_patterns,
bool recursive = false,
uint04 max_count = Constantuint04 >::Max ) const
nodiscard

Retrieves children matching include patterns while excluding others, using StringView patterns.

Parameters
[in]include_patternsThe patterns to include.
[in]exclude_patternsThe patterns to exclude.
[in]recursiveWhether to search subdirectories recursively.
[in]max_countThe maximum number of results to return.
Returns
A FileBuffer containing the matching children.

◆ getChildrenMatching() [5/5]

FileBuffer File::getChildrenMatching ( const StringView & include_pattern,
bool recursive = false,
uint04 max_count = Constantuint04 >::Max ) const
nodiscard

Retrieves children of this directory matching a pattern.

Parameters
[in]include_patternThe pattern to match against (e.g., "*.txt").
[in]recursiveWhether to search subdirectories recursively.
[in]max_countThe maximum number of results to return.
Returns
A FileBuffer containing the matching children.

◆ getCreationTime()

Time File::getCreationTime ( ) const
nodiscard

Gets the creation time of the file.

Returns
The creation Time.

◆ getData()

Buffer< uint01 > File::getData ( )
nodiscard

Reads the entire file contents into a byte buffer.

Returns
A Buffer containing the file data.

◆ getDataExtended()

HighCapacityBuffer< uint01 > File::getDataExtended ( )
nodiscard

Reads the entire file contents into a high-capacity byte buffer for large files.

Returns
A HighCapacityBuffer containing the file data.

◆ getDriveDescription()

String File::getDriveDescription ( ) const
nodiscard

Retrieves a human-readable description of the drive this file resides on.

Returns
A String describing the drive.

References String::String().

◆ getFileTimes()

void File::getFileTimes ( Time & modified_time,
Time & creation_time,
Time & access_time ) const

Retrieves all three file timestamps at once.

Parameters
[in]modified_timeReceives the last modified time.
[in]creation_timeReceives the creation time.
[in]access_timeReceives the last access time.

◆ getFolderName()

StringView File::getFolderName ( bool trailing_mark = false) const
nodiscard

Retrieves the folder name portion of the file path.

Parameters
[in]trailing_markWhether to include a trailing path separator.
Returns
A StringView of the folder name.

◆ getModifiedTime()

Time File::getModifiedTime ( ) const
nodiscard

Gets the last modified time of the file.

Returns
The modification Time.

◆ getParentDirectory()

File File::getParentDirectory ( ) const

Gets the parent directory of this file.

Returns
A File representing the parent directory.

References File().

Referenced by ShaderTools::compileShader().

◆ getPath()

StringView File::getPath ( uint01 file_parts) const
nodiscard

Retrieves a subset of the file path based on the specified parts.

Parameters
[in]file_partsA bitmask of FilePart flags indicating which parts to return.
Returns
A StringView of the requested path components.

Referenced by ShaderTools::compileShader().

◆ getUUID()

UUID File::getUUID ( ) const
nodiscard

Gets a UUID that uniquely identifies this file on the filesystem.

Returns
The UUID of the file.

◆ hasNullBytes()

bool File::hasNullBytes ( uint08 max_length = Constantuint08 >::Max)

Checks whether the file contains null bytes within the specified range.

Parameters
[in]max_lengthThe maximum number of bytes to scan.
Returns
True if null bytes are found.

◆ isDirectory()

bool File::isDirectory ( ) const
nodiscard

Checks whether this path refers to a directory.

Returns
True if this path is a directory.

◆ isDrive()

bool File::isDrive ( ) const
nodiscard

Checks whether this path refers to a drive root.

Returns
True if this path is a drive.

◆ isHidden()

bool File::isHidden ( ) const
nodiscard

Checks whether this file is hidden.

Returns
True if the file has the hidden attribute.

◆ isIDSep()

bool File::isIDSep ( const char & path)
staticnodiscard

Checks whether a character is an ID separator.

Parameters
[in]pathThe character to check.
Returns
True if the character is an ID separator.

References PathSep, and PathSepS.

◆ isMTP()

bool File::isMTP ( ) const

Checks whether this file path refers to an MTP (Media Transfer Protocol) device.

Returns
True if this is an MTP path.

◆ isOpen()

bool File::isOpen ( ) const
nodiscard

Checks whether this file is currently open.

Returns
True if the file is open for reading or writing.

◆ isPathSep()

bool File::isPathSep ( const char & path)
staticnodiscard

Checks whether a character is a path separator.

Parameters
[in]pathThe character to check.
Returns
True if the character is a path separator.

◆ makeReadOnly()

void File::makeReadOnly ( bool read_only)

Sets or clears the read-only attribute on this file.

Parameters
[in]read_onlyWhether the file should be read-only.

◆ moveTo()

bool File::moveTo ( File & file,
bool override_file,
LogPtr log = LogPtr(),
bool is_source_temp = false )

Moves this file to a new location.

Parameters
[in]fileThe destination file.
[in]override_fileWhether to overwrite the destination if it exists.
[in]logOptional log for reporting progress or errors.
[in]is_source_tempWhether the source file is a temporary file.
Returns
True if the move succeeded.

References File().

◆ MTPDevices()

FileBuffer File::MTPDevices ( )
staticnodiscard

Retrieves all connected MTP (Media Transfer Protocol) devices.

Returns
A FileBuffer containing the available MTP devices.

◆ nameSort()

bool File::nameSort ( const File & i,
const File & j )
staticnodiscard

Comparison function for sorting files by name.

Parameters
[in]iThe first file to compare.
[in]jThe second file to compare.
Returns
True if i should come before j when sorted by name.

References File().

◆ open()

FILE * File::open ( OpenMode mode,
bool append = false )

Opens the file with the specified mode.

Parameters
[in]modeThe OpenMode to use.
[in]appendWhether to open in append mode rather than overwriting.
Returns
The FILE pointer for the opened file, or nullptr on failure.

References append().

Referenced by ShaderTools::compileShader().

◆ operator()()

size_t File::operator() ( ) const
inline

Functor operator for use as a hash key in standard containers.

Returns
The hash value of this file path.

Definition at line 537 of file File.h.

References String::hash().

◆ operator<<() [1/5]

bool File::operator<< ( const Buffer< uint01 > & values)

Writes a byte buffer to the file.

Parameters
[in]valuesThe byte buffer to write.
Returns
True if the write succeeded.

◆ operator<<() [2/5]

bool File::operator<< ( const fltp04 & value)

Writes a 32-bit floating-point value to the file.

Parameters
[in]valueThe value to write.
Returns
True if the write succeeded.

◆ operator<<() [3/5]

bool File::operator<< ( const fltp08 & value)

Writes a 64-bit floating-point value to the file.

Parameters
[in]valueThe value to write.
Returns
True if the write succeeded.

◆ operator<<() [4/5]

bool File::operator<< ( const HighCapacityBuffer< uint01 > & values)

Writes a high-capacity byte buffer to the file.

Parameters
[in]valuesThe high-capacity byte buffer to write.
Returns
True if the write succeeded.

◆ operator<<() [5/5]

bool File::operator<< ( const StringView & value)

Writes a string to the file.

Parameters
[in]valueThe string to write.
Returns
True if the write succeeded.

◆ operator=() [1/3]

File & File::operator= ( const File & value)

Copy assignment operator.

Parameters
[in]valueThe File to copy from.
Returns
A reference to this File.

References File().

◆ operator=() [2/3]

File & File::operator= ( File && value)
noexcept

Move assignment operator.

Parameters
[in]valueThe File to move from.
Returns
A reference to this File.

References File().

◆ operator=() [3/3]

File & File::operator= ( String & value)

Assignment operator from a String reference.

Parameters
[in]valueThe String to assign from.
Returns
A reference to this File.

References File(), and String::String().

◆ parentDirectoryExists()

bool File::parentDirectoryExists ( ) const
nodiscard

Checks whether the parent directory of this file exists.

Returns
True if the parent directory exists.

◆ pathID()

const String & File::pathID ( ) const
inline

Gets the path identifier string for this file.

Returns
A const reference to the path ID string.

Definition at line 478 of file File.h.

References String::String(), and m_id.

◆ pathNameID()

StringView File::pathNameID ( ) const

Gets a combined path and name identifier for this file.

Returns
A StringView of the path-name identifier.

◆ relativePathTo()

String File::relativePathTo ( const File & reference) const

Computes the relative path from this file to a reference file.

Parameters
[in]referenceThe reference file to compute the relative path to.
Returns
A String containing the relative path.

References File(), and String::String().

◆ resolveMTPPath()

bool File::resolveMTPPath ( ) const

Resolves the actual filesystem path from an MTP device path.

Returns
True if the path was successfully resolved.

◆ resolveNameFromMTPPath()

bool File::resolveNameFromMTPPath ( )

Resolves the display name from an MTP device path.

Returns
True if the name was successfully resolved.

◆ setFolderName()

void File::setFolderName ( const StringView & folder_name)

Sets the folder name portion of the file path.

Parameters
[in]folder_nameThe new folder name.

◆ setFromDisplayString()

void File::setFromDisplayString ( const StringView & display_string)

Sets this file path from a user-friendly display string.

Parameters
[in]display_stringThe display string to parse.

◆ setPath()

void File::setPath ( const StringView & path,
uint01 part )

Sets a specific part of the file path.

Parameters
[in]pathThe new value for the path part.
[in]partThe FilePart flag indicating which part to set.

Referenced by ShaderTools::compileShader(), and TranslationTools::makeTranslation().

◆ SystemDrives()

FileBuffer File::SystemDrives ( )
staticnodiscard

Retrieves all system drives.

Returns
A FileBuffer containing the available system drives.

◆ TempFileFolder()

File File::TempFileFolder ( )
staticnodiscard

Gets the system temporary file folder.

Returns
A File representing the temporary file directory.

References File().

◆ toDisplayString()

String File::toDisplayString ( )

Converts this file path to a user-friendly display string.

Returns
A formatted display string.

References String::String().

◆ typeSort()

bool File::typeSort ( const File & i,
const File & j )
staticnodiscard

Comparison function for sorting files by type (extension).

Parameters
[in]iThe first file to compare.
[in]jThe second file to compare.
Returns
True if i should come before j when sorted by type.

References File().

◆ updateAccessedTime() [1/2]

bool File::updateAccessedTime ( ) const

Updates the last accessed time of the file to the current time.

Returns
True if the update succeeded.

◆ updateAccessedTime() [2/2]

bool File::updateAccessedTime ( Time access_time) const

Updates the last accessed time of the file to a specific time.

Parameters
[in]access_timeThe time to set as the last access time.
Returns
True if the update succeeded.

◆ updateCache()

void File::updateCache ( const FileCachedData & cache)

Updates the cached file metadata with the provided data.

Parameters
[in]cacheThe new cached data to store.

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