lfilesystem
0.0.1
C++ filesystem library
|
Represents a temporary file. More...
#include <lfilesystem_File.h>
Public Member Functions | |
TempFile (const Path &filepath, bool destroyOnDelete=true) | |
Creates a temporary file with the specified path. More... | |
TempFile (const TempFile &)=delete | |
~TempFile () final | |
The temporary file will be deleted from the filesystem when this object is destroyed, if this object was constructed with the destroyOnDelete parameter being true . More... | |
TempFile & | operator= (const TempFile &)=delete |
Moving | |
TempFile (TempFile &&other) noexcept | |
Move constructor. More... | |
TempFile & | operator= (TempFile &&other) noexcept |
Move assignment operator. More... | |
Public Member Functions inherited from limes::files::File | |
File (const File &)=default | |
File (File &&)=default | |
Iterator | begin () const |
Returns an iterator to the first line in this file. More... | |
std::optional< File > | duplicate () const noexcept |
Duplicates this file within its directory. More... | |
Iterator | end () const |
Returns an iterator to the last line in this file. More... | |
FilesystemEntry ()=default | |
Creates a FilesystemEntry with an empty path. More... | |
FilesystemEntry (const FilesystemEntry &)=default | |
FilesystemEntry (const Path &pathToUse) | |
Creates a FilesystemEntry referring to the specified path. More... | |
FilesystemEntry (FilesystemEntry &&)=default | |
CFile | getCfile (CFile::Mode mode=CFile::Mode::Read) const noexcept |
Returns a CFile referring to this filepath. More... | |
File & | operator= (const File &)=default |
File & | operator= (File &&)=default |
bool | resize (std::uintmax_t newSizeInBytes, bool allowTruncation=true, bool allowIncreasing=true) const noexcept |
Resizes this file to the set number of bytes. More... | |
std::string | getFilename (bool includeExtension=false) const |
Returns this file's filename. More... | |
std::string | getFileExtension () const |
Returns this file's file extension, if any. More... | |
bool | hasFileExtension (const std::string_view &extension) const |
Returns true if this file has the specified file extension. More... | |
bool | hasFileExtension () const |
Returns true if this file has a file extension. More... | |
bool | isMacOSBundle () const noexcept |
Returns true if this file is a MacOS bundle. More... | |
bool | isFile () const noexcept final |
Returns this file's filename. More... | |
bool | isDirectory () const noexcept final |
Returns this file's filename. More... | |
bool | isSymLink () const noexcept final |
Returns this file's filename. More... | |
bool | replaceFileExtension (const std::string_view &newFileExtension, bool renameOnDisk=true) |
Replaces the file extension of this file. More... | |
File & | operator= (const Path &newPath) |
Assigns this object to refer to a new path. More... | |
File & | operator= (const std::string_view &newPath) |
Assigns this object to refer to a new path. More... | |
std::string | loadAsString () const noexcept |
Loads the file's contents as a string. More... | |
std::vector< std::string > | loadAsLines () const |
Loads the file's contents as a vector of strings, with each string containing the contents of one line of the file. More... | |
std::unique_ptr< std::ifstream > | getInputStream () const |
Returns a standard input stream for reading from this file. More... | |
bool | overwrite (const char *const data, std::size_t numBytes) const noexcept |
Replaces the file's contents with the given data. More... | |
bool | overwrite (const std::string_view &text) const noexcept |
Replaces the file's contents with the given data. More... | |
std::unique_ptr< std::ofstream > | getOutputStream () const |
Returns a standard output stream for writing to this file. More... | |
bool | append (const char *const data, std::size_t numBytes) const noexcept |
Appends the given data to the file's current contents. More... | |
bool | append (const std::string_view &text) const noexcept |
Appends the given data to the file's current contents. More... | |
bool | prepend (const char *const data, std::size_t numBytes) const noexcept |
Prepends the given data to the file's current contents. More... | |
bool | prepend (const std::string_view &text) const noexcept |
Prepends the given data to the file's current contents. More... | |
std::optional< File > | createHardLink (const Path &path) const |
Creates a hard link to this file at the specified path . More... | |
std::uintmax_t | getHardLinkCount () const noexcept |
Returns the number of hard links referring to this underlying filesystem object. More... | |
Public Member Functions inherited from limes::files::FilesystemEntry | |
FilesystemEntry (const FilesystemEntry &)=default | |
FilesystemEntry (FilesystemEntry &&)=default | |
virtual | ~FilesystemEntry ()=default |
Destructor. More... | |
bool | copyFrom (const FilesystemEntry &source, CopyOptions options=CopyOptions::update_existing) const noexcept |
bool | copyFrom (const Path &source, CopyOptions options=CopyOptions::update_existing) const noexcept |
Overwriting. More... | |
FilesystemEntry & | operator= (const FilesystemEntry &)=default |
FilesystemEntry & | operator= (FilesystemEntry &&)=default |
bool | revealToUserInFileBrowser () const |
Uses the system's native file browser to display this file to the user. More... | |
FilesystemEntry ()=default | |
Creates a FilesystemEntry with an empty path. More... | |
FilesystemEntry (const Path &pathToUse) | |
Creates a FilesystemEntry referring to the specified path. More... | |
FilesystemEntry & | operator= (const Path &newPath) |
Assigns the path this filesystem entry represents. More... | |
FilesystemEntry & | operator= (const std::string_view &newPath) |
Assigns the path this filesystem entry represents. More... | |
FilesystemEntry & | assignPath (const Path &newPath) noexcept |
Assigns the path this filesystem entry represents. More... | |
bool | operator== (const FilesystemEntry &other) const noexcept |
Compares this filesystem entry's absolute path with the other one's for equality. More... | |
bool | operator== (const Path &other) const noexcept |
Compares this filesystem entry's absolute path with the other one's for equality. More... | |
bool | operator!= (const FilesystemEntry &other) const noexcept |
Compares this filesystem entry's absolute path with the other one's for equality. More... | |
bool | operator!= (const Path &other) const noexcept |
Compares this filesystem entry's absolute path with the other one's for equality. More... | |
bool | operator< (const FilesystemEntry &other) const noexcept |
Lexicographically compares this filesystem entry's absolute path with another path. More... | |
bool | operator> (const FilesystemEntry &other) const noexcept |
Lexicographically compares this filesystem entry's absolute path with another path. More... | |
bool | operator< (const Path &other) const noexcept |
Lexicographically compares this filesystem entry's absolute path with another path. More... | |
bool | operator> (const Path &other) const noexcept |
Lexicographically compares this filesystem entry's absolute path with another path. More... | |
FilesystemEntry | operator/ (const std::string_view &subpathName) const |
Returns a new FilesystemEntry referring to a subpath of this one. More... | |
FilesystemEntry & | operator/= (const std::string_view &subpathName) |
Assigns this object's path to a subpath of the current path. More... | |
FilesystemEntry & | changeName (const std::string_view &newName) |
Changes the last section of the path (the filename). More... | |
bool | makeAbsoluteRelativeTo (const Path &basePath) noexcept |
If the path this object holds is already absolute, this function does nothing and returns false. More... | |
bool | makeAbsoluteRelativeToCWD () noexcept |
Similar to makeAbsoluteRelativeTo() , but uses the current working directory as the base path. More... | |
Path | getPath (bool makePreferred=false) const noexcept |
Returns the current path held by this object. More... | |
Path | getAbsolutePath (bool makePreferred=false) const noexcept |
Returns the full, absolute path of this filesystem entry. More... | |
operator Path () const noexcept | |
Converts this filesystem entry to the path it holds. More... | |
std::string | getName () const noexcept |
Returns the last section of the path (the filename). More... | |
Directory | getDirectory () const |
Returns the directory containing this filesystem entry. More... | |
Directory | getParentDirectory () const |
Returns the parent directory of this filesystem entry. More... | |
bool | isBelow (const Directory &directory, std::size_t depthLimit=50) const |
Returns true if this filesystem entry is in a subdirectory of the given directory – ie, if that directory is a parent or grandparent of this filepath. More... | |
bool | isAbsolutePath () const noexcept |
Returns true if the path this object holds is an absolute path. More... | |
bool | isRelativePath () const noexcept |
Returns true if the path this object holds is a relative path. More... | |
bool | isValid () const noexcept |
Returns true if this object holds a valid filesystem path. More... | |
bool | isHidden () const |
Returns true if this path is a hidden file or directory. More... | |
FilesystemEntry | getSibling (const std::string_view &siblingName) const |
Returns a filesystem entry with the given name in the same directory as this one. More... | |
bool | exists () const noexcept |
Returns true if the filesystem object this object refers to exists on disk. More... | |
operator bool () const noexcept | |
Returns true if this filesystem object exists. More... | |
virtual std::uintmax_t | sizeInBytes () const |
Returns the size, in bytes, of the filesystem entry referred to by this object. More... | |
Time | getLastModificationTime () const noexcept |
Returns the last modification time of the filesystem entry. More... | |
std::optional< Volume > | getVolume () const noexcept |
Returns a Volume object representing the logical filesystem volume that this object exists on. More... | |
std::optional< File > | getFileObject () const noexcept |
If this object refers to a file, constructs a File object referring to the same file. More... | |
std::optional< Directory > | getDirectoryObject () const noexcept |
If this object refers to a directory, constructs a Directory object referring to the same directory. More... | |
std::optional< SymLink > | getSymLinkObject () const noexcept |
If this object refers to a symbolic link, constructs a SymLink object referring to the same link. More... | |
virtual bool | createIfDoesntExist () const noexcept |
Creates the filesystem entry this object refers to, if it doesn't already exist. More... | |
bool | deleteIfExists () const noexcept |
Deletes the filesystem entry this object refers to, if it exists. More... | |
bool | moveToTrash () noexcept |
Attempts to move this filesystem object to the system's trash folder. More... | |
void | touch () const |
If the filesystem entry this object refers do doesn't exist, this function creates it. More... | |
bool | touch_noCreate () const |
The same as touch() , except this function does not create the filesystem entry if it didn't already exist. More... | |
bool | rename (const Path &newPath) noexcept |
Renames this filesystem object to a new path. More... | |
bool | setPermissions (FSPerms permissions, PermOptions options=PermOptions::replace) const noexcept |
Sets the permissions for the filesystem entry. More... | |
Permissions | getPermissions () const |
Returns the current permissions of the filesystem entry this object refers to. More... | |
bool | copyTo (const Path &dest, CopyOptions options=CopyOptions::update_existing) const noexcept |
Creates a copy of this filesystem entry at a new location on disk. More... | |
bool | copyTo (const FilesystemEntry &dest, CopyOptions options=CopyOptions::update_existing) const noexcept |
Creates a copy of this filesystem entry at a new location on disk. More... | |
std::optional< FilesystemEntry > | copyToDirectory (const Path &destDirectory, CopyOptions options=CopyOptions::update_existing) const noexcept |
Creates a copy of this filesystem object, with the same filename, in a different directory. More... | |
Static Public Member Functions | |
static TempFile | getNextFile () |
Returns a new temporary file. More... | |
Static Public Member Functions inherited from limes::files::File | |
static File | getCurrentExecutable () |
Returns a file representing the location of the executable file that launched the current process. More... | |
static File | getCurrentModule () |
Returns a file representing the location of the current code module. More... | |
Additional Inherited Members | |
Public Types inherited from limes::files::FilesystemEntry | |
using | PermOptions = std::filesystem::perm_options |
Options bitfield for setting permissions. More... | |
using | CopyOptions = std::filesystem::copy_options |
Options bitfield for copying. More... | |
using | Time = std::filesystem::file_time_type |
A time point used for filesystem time. More... | |
Related Functions inherited from limes::files::File | |
std::ostream & | operator<< (std::ostream &os, const File &file) |
Writes the file's contents to the output stream. More... | |
std::istream & | operator>> (std::istream &is, const File &file) |
Reads content from the input stream, and overwrites the file with it. More... | |
Related Functions inherited from limes::files::FilesystemEntry | |
std::ostream & | operator<< (std::ostream &os, const FilesystemEntry &value) |
Writes a FilesystemEntry's path to the output stream. More... | |
Represents a temporary file.
This object will create the temporary file when the object is constructed, and by default will destroy the file when the object is destroyed (though this behavior can be turned off).
The temporary file will reside in the directory returned by dirs::temp()
.
If you don't care about filenames and just need a temporary file to work with, use the static method getNextFile()
.
Definition at line 382 of file lfilesystem_File.h.
|
explicit |
Creates a temporary file with the specified path.
The file will be created on the filesystem when this object is constructed.
filepath | The path of the temporary file. If this is a relative path, then the directory returned by dirs::temp() will be prepended to the path. |
destroyOnDelete | If true, the file will be deleted from the filesystem when this object is destroyed. If false, the file will be left on disk when this object is deleted. |
|
final |
The temporary file will be deleted from the filesystem when this object is destroyed, if this object was constructed with the destroyOnDelete
parameter being true
.
|
noexcept |
Move constructor.
|
static |
Returns a new temporary file.
This will create an unused filename in the directory returned by dirs::temp()
. The TempFile returned by this function will delete the file it references on disk when it is destroyed.