libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Dir Class Reference

Provides directory operations using std::filesystem. More...

#include <dir.h>

Public Member Functions

 Dir ()=default
 Constructs a Dir with an empty path.
 
 Dir (const FilePath &path)
 Constructs a Dir for the given path.
 
 Dir (const String &path)
 Constructs a Dir from a String path.
 
 Dir (const char *path)
 Constructs a Dir from a C string path.
 
FilePath path () const
 Returns the directory path.
 
bool exists () const
 Returns true if the directory exists.
 
bool isEmpty () const
 Returns true if the directory is empty.
 
List< FilePathentryList () const
 Returns a list of all entries in the directory.
 
List< FilePathentryList (const String &filter) const
 Returns a filtered list of entries in the directory.
 
Error mkdir () const
 Creates this directory.
 
Error mkpath () const
 Creates this directory and all parent directories.
 
Error remove () const
 Removes this directory (must be empty).
 
Error removeRecursively () const
 Removes this directory and all its contents.
 

Static Public Member Functions

static Dir current ()
 Returns a Dir for the current working directory.
 
static Dir home ()
 Returns a Dir for the user's home directory.
 
static Dir temp ()
 Returns a Dir for the system temp directory.
 
static Error setCurrent (const FilePath &path)
 Sets the current working directory.
 

Detailed Description

Provides directory operations using std::filesystem.

Dir is a simple utility class (not ObjectBase) that wraps std::filesystem directory operations with the promeki API

Example
Dir dir("/tmp/output");
if(!dir.exists()) dir.mkpath();
StringList files = dir.entryList();
for(const String &f : files) { ... }
Provides directory operations using std::filesystem.
Definition dir.h:34
Dynamic array container wrapping std::vector.
Definition list.h:40
Manages a list of strings.
Definition stringlist.h:21
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
conventions.

Constructor & Destructor Documentation

◆ Dir() [1/3]

Dir::Dir ( const FilePath path)
inline

Constructs a Dir for the given path.

Parameters
pathThe directory path.

◆ Dir() [2/3]

Dir::Dir ( const String path)
inline

Constructs a Dir from a String path.

Parameters
pathThe directory path string.

◆ Dir() [3/3]

Dir::Dir ( const char path)
inline

Constructs a Dir from a C string path.

Parameters
pathThe directory path string.

Member Function Documentation

◆ current()

static Dir Dir::current ( )
static

Returns a Dir for the current working directory.

Returns
A Dir wrapping the current directory.

◆ entryList() [1/2]

List< FilePath > Dir::entryList ( ) const

Returns a list of all entries in the directory.

Returns
A List of FilePath entries.

◆ entryList() [2/2]

List< FilePath > Dir::entryList ( const String filter) const

Returns a filtered list of entries in the directory.

Uses fnmatch() for glob-style pattern matching.

Parameters
filterThe glob pattern to match filenames against.
Returns
A List of matching FilePath entries.

◆ exists()

bool Dir::exists ( ) const

Returns true if the directory exists.

Returns
true if the path refers to an existing directory.

◆ home()

static Dir Dir::home ( )
static

Returns a Dir for the user's home directory.

Returns
A Dir wrapping the home directory.

◆ isEmpty()

bool Dir::isEmpty ( ) const

Returns true if the directory is empty.

A non-existent directory is considered empty.

Returns
true if the directory has no entries.

◆ mkdir()

Error Dir::mkdir ( ) const

Creates this directory.

The parent directory must already exist.

Returns
Error::Ok on success, or an error on failure.

◆ mkpath()

Error Dir::mkpath ( ) const

Creates this directory and all parent directories.

Returns
Error::Ok on success, or an error on failure.

◆ path()

FilePath Dir::path ( ) const
inline

Returns the directory path.

Returns
The path as a FilePath.

◆ remove()

Error Dir::remove ( ) const

Removes this directory (must be empty).

Returns
Error::Ok on success, or an error on failure.

◆ removeRecursively()

Error Dir::removeRecursively ( ) const

Removes this directory and all its contents.

Returns
Error::Ok on success, or an error on failure.

◆ setCurrent()

static Error Dir::setCurrent ( const FilePath path)
static

Sets the current working directory.

Parameters
pathThe new working directory.
Returns
Error::Ok on success, or an error on failure.

◆ temp()

static Dir Dir::temp ( )
static

Returns a Dir for the system temp directory.

Returns
A Dir wrapping the temp directory.

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