ImFusion SDK 4.3
TemporaryDirectory Class Reference

#include <ImFusion/Core/Filesystem/TemporaryDirectory.h>

Temporary directory which deletes itself upon going out of scope. More...

+ Inheritance diagram for TemporaryDirectory:

Detailed Description

Temporary directory which deletes itself upon going out of scope.

Public Types

enum class  Policy { Create , CreateRecursive , DoNotCreate }
 TemporaryDirectory Construction Policy.
 
- Public Types inherited from Directory
enum class  SortOption {
  Unsorted = 0x0 , Name = 0x1 , Extension = 0x2 , Size = 0x4 ,
  Time = 0x8 , IgnoreCase = 0x10 , DirsFirst = 0x20 , DirsLast = 0x40 ,
  Reversed = 0x80
}
 Sorting options for paths inside a directory One of the first 5 options (Unsorted, Name, Extension, Size, Time) might be or-combined with one or multiple of the following options. More...
 
using SortOptions = Flags<SortOption>
 

Public Member Functions

 TemporaryDirectory (const Path &path={}, Policy policy=Policy::CreateRecursive)
 Constructs a TemporaryDirectory with a given path and policy.
 
- Public Member Functions inherited from Directory
 Directory (const Path &path)
 Create a new Directory instance for the given path.
 
 Directory (const std::string &path)
 Create a new Directory instance for the given path.
 
 Directory (const char *path)
 Create a new Directory instance for the given path.
 
 operator Path () const
 Allow for implicit conversion to a Path.
 
Path path () const
 Gets the path of the directory.
 
std::string string () const
 Gets the path of the directory 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 directory, convenience function for path().fileName().
 
bool exists () const
 Check if the directory exists and is actually a directory.
 
bool isEmpty () const
 Check if the directory is empty.
 
bool isWritable () const
 Checks if the directory exists and is writable, in other words if a file can be created in it.
 
bool contains (const std::string &filename) const
 Check if the directory contains a file or subdirectory named filename.
 
std::vector< Pathscan (const std::function< bool(const Path &)> &filter=nullptr, SortOptions options=SortOption::Name) const
 Scans the directory and collects the paths inside that pass the (optional) lambda filter.
 
std::vector< PathscanRecursive (const std::function< bool(const Path &)> &filter=nullptr) const
 Recursively scans the directory and collects the paths inside that pass the (optional) lambda filter.
 
bool copyTo (const Path &destination, Flags< CopyOptions > copyOptions=CopyOptions::None, std::function< bool(const Path &sourcePath)> filter=nullptr) const
 Copies this directory and its contents to destination based on the provided options and optional filter.
 
bool rename (const Path &newName)
 Renames the directory.
 
bool remove () const
 Delete the directory if it's empty.
 
bool removeRecursive () const
 Delete the directory and all of its contents.
 
bool removeContents () const
 Delete all the contents of the directory without deleting the directory itself.
 
bool create () const
 Creates the directory on the filesystem (the parent directory must already exist).
 
bool createRecursive () const
 Recursively create the directory (including parent directories if needed).
 

Additional Inherited Members

- Protected Member Functions inherited from NotCopyable
 NotCopyable (NotCopyable &&) noexcept=default
 
NotCopyableoperator= (NotCopyable &&) noexcept=default
 
 NotCopyable (const NotCopyable &)=delete
 
NotCopyableoperator= (const NotCopyable &)=delete
 

Constructor & Destructor Documentation

◆ TemporaryDirectory()

TemporaryDirectory ( const Path & path = {},
Policy policy = Policy::CreateRecursive )
explicit

Constructs a TemporaryDirectory with a given path and policy.

Parameters
pathThe path where the temporary directory will be created. Relative paths are considered relative to the current working directory.
  • If path is empty (default), a directory with a randomized name is created in the system's temporary file directory.
  • Otherwise path will be used for the temporary directory. The path can optionally include percent sign characters to specify replacement by a random hexadecimal digit. For example:
    TemporaryDirectory("/my/tempfile/directory%%/%%%%");
    TemporaryDirectory(const Path &path={}, Policy policy=Policy::CreateRecursive)
    Constructs a TemporaryDirectory with a given path and policy.
policyThe policy of how the temporary directory should be created.
  • Create: Create the directory immediately upon construction. If path is not empty, and the parent directory of the given path doesn't exit, this will not create them.
  • CreateRecursive (default): Create the directory and parent directories immediately upon construction.
  • DoNotCreate: Will not create the directory on the filesystem. You can subsequently create the directory manually by calling create().

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close