![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/Filesystem/File.h>
Entity representing a file in the filesystem. More...
Inheritance diagram for File:Entity representing a file in the filesystem.
The file does not necessarily exist and File will not perform any checks whether the given file name represents a valid identifier for the current platform.
The underlying Path will always be absolute: if you construct an instance using a relative path the constructor will make it absolute using the currentWorkingDirectory() and all subsequent calls to member functions will correspond to that absolute path.
Public Member Functions | |
| File (const Path &path) | |
| Create a new File instance for the given path. | |
| File (const std::string &path) | |
| Create a new File instance for the given path. | |
| File (const char *path) | |
| Create a new File instance for the given path. | |
| operator Path () const | |
| Allow for implicit conversion to a Path. | |
Query file properties | |
| const Path & | path () const |
| Gets the path of the file. | |
| std::string | string () const |
| Gets the path of the file as string. | |
| Directory | parentDirectory () const |
Returns the absolute path to the parent directory, convenience function for Directory(path().parentPath()). | |
| Path | parentPath () const |
Returns the absolute path to the parent directory, convenience function for path().parentPath(). | |
| std::string | name () const |
| Gets the name of the file including the extension. | |
| bool | exists () const |
| Checks if the file exists and actually is a file. | |
| bool | isExecutable () const |
| Checks if the file is executable (and exists). | |
| ByteSize | size () const |
| Gets the size of the file in bytes. | |
| time_t | lastModified () const |
| Gets the time of the last modification to the file. | |
Perform filesystem interactions | |
| bool | copyTo (const Path &destination, Flags< CopyOptions > copyOptions=CopyOptions::None) const |
| Copies this single file to destination using the provided copy options. | |
| bool | rename (const Path &newName) |
| Renames the file, including extension. | |
| bool | remove () const |
| Delete the file. | |
| bool | create () const |
| Creates the file without any content. | |
| bool | createRecursive () const |
| Create the file without any content including the parent directory if needed. | |
Read/write content from/to the file | |
| ByteBuffer | readBinary () const |
| Read the entire content of the file in a binary fashion and return it as buffer. | |
| std::vector< std::string > | readText () const |
| Read the entire content of the file in a text-based fashion and return it as vector of lines. | |
| bool | writeBinary (const ByteBufferView &data) const |
| Write the given data to the file in a binary fashion. | |
| bool | writeText (const std::vector< std::string > &lines) const |
Write the given list of strings into the file in a text-based fashion inserting a newline character (\n) after each line. | |
| bool | appendBinary (const ByteBufferView &data) const |
| Append the given data to the file in a binary fashion. | |
| bool | appendText (const std::vector< std::string > &lines) const |
Append the given list of strings into the file in a text-based fashion inserting a newline character (\n) after each line. | |
| std::ifstream | openForReading (std::ios_base::openmode openmode=std::ios_base::in) const |
| Create an input file stream for reading from the file. | |
| std::ofstream | openForWriting (std::ios_base::openmode openmode=std::ios_base::out) const |
| Create an output file stream for writing to the file. | |
Create a new File instance for the given path.
If path is relative it will be made absolute wrt. currentWorkingDirectory() and all future calls to member functions will use this absolute path.
|
explicit |
Create a new File instance for the given path.
If path is relative it will be made absolute wrt. currentWorkingDirectory() and all future calls to member functions will use this absolute path.
|
explicit |
Create a new File instance for the given path.
If path is relative it will be made absolute wrt. currentWorkingDirectory() and all future calls to member functions will use this absolute path.
| bool isExecutable | ( | ) | const |
Checks if the file is executable (and exists).
On Windows, the file must be a 32- or 64-bit "Windows-based" application (according to GetBinaryType()) On Unix, the file must grant the executable permission (according to access())
| bool copyTo | ( | const Path & | destination, |
| Flags< CopyOptions > | copyOptions = CopyOptions::None ) const |
Copies this single file to destination using the provided copy options.
| destination | Target file name of the copy. If destination describes an existing directory, then behaves as copyTo(destination / source.filename(), copyOptions). |
| copyOptions | Optional flags to control the behavior of this function. Flags irrelevant to files are ignored and do not report an error. |
| bool rename | ( | const Path & | newName | ) |
Renames the file, including extension.
Returns true upon success.
| bool remove | ( | ) | const |
Delete the file.
If the path is a symbolic link, it removes only the link. If the file did not exist in the first place, does nothing.
| bool create | ( | ) | const |
Creates the file without any content.
This function will fail if the parent directory does not exist, use createRecursive() for this functionality.
| ByteBuffer readBinary | ( | ) | const |
Read the entire content of the file in a binary fashion and return it as buffer.
| std::vector< std::string > readText | ( | ) | const |
Read the entire content of the file in a text-based fashion and return it as vector of lines.
This function will use std::ifstream in text mode internally and consume the content using std::getline() until the end of the file is reached. The newline characters (\n) after each line are removed; no further post-processing is performed. The corresponding platform-dependent behavior of C-style text file I/O applies.
| bool writeBinary | ( | const ByteBufferView & | data | ) | const |
Write the given data to the file in a binary fashion.
If the file does not exist, it will be created recursively. If the file already exists, all content will be overwritten.
| bool writeText | ( | const std::vector< std::string > & | lines | ) | const |
Write the given list of strings into the file in a text-based fashion inserting a newline character (\n) after each line.
If the file already exists, all content will be overwritten. This function will use std::ofstream in text mode internally, thus the corresponding platform-dependent behavior of C-style text file I/O applies.
| bool appendBinary | ( | const ByteBufferView & | data | ) | const |
Append the given data to the file in a binary fashion.
If the file does not exist, it will be created recursively.
| bool appendText | ( | const std::vector< std::string > & | lines | ) | const |
Append the given list of strings into the file in a text-based fashion inserting a newline character (\n) after each line.
This function will use std::ofstream in text mode internally, thus the corresponding platform- dependent behavior of C-style text file I/O applies.
| std::ifstream openForReading | ( | std::ios_base::openmode | openmode = std::ios_base::in | ) | const |
Create an input file stream for reading from the file.
Convenience function for calling std::ifstream(Platform::widen(file.path().string(), openmode).
| openmode | Bitmask defining stream open mode, directly forwarded to std::ifstream constructor |
| std::ofstream openForWriting | ( | std::ios_base::openmode | openmode = std::ios_base::out | ) | const |
Create an output file stream for writing to the file.
Convenience function for calling std::ofstream(Platform::widen(file.path().string(), openmode).
| openmode | Bitmask defining stream open mode, directly forwarded to std::ofstream constructor |