reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

#include <ofFileUtils.h>

Public Types

enum  SortMode { SORT_FAST , SORT_NATURAL , SORT_BY_DATE }
 

Public Member Functions

 ofDirectory ()
 
 ofDirectory (const of::filesystem::path &path)
 
void open (const of::filesystem::path &path)
 
void openFromCWD (const of::filesystem::path &path)
 
void close ()
 Close the currently open path.
 
bool create (bool recursive=false)
 
bool exists () const
 
std::string path () const
 
std::string getAbsolutePath () const
 
bool canRead () const
 
bool canWrite () const
 
bool canExecute () const
 
bool isDirectory () const
 
bool isHidden () const
 
void setWriteable (bool writeable=true)
 
 OF_DEPRECATED_MSG ("Use ofDirectory::setWriteable(!flag).", void setReadOnly(bool flag))
 
void setReadable (bool readable=true)
 
void setExecutable (bool executable=true)
 
void setShowHidden (bool showHidden)
 
bool copyTo (const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false)
 
bool moveTo (const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false)
 
bool renameTo (const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false)
 
bool remove (bool recursive)
 
void allowExt (const std::string &extension)
 
std::size_t listDir (const of::filesystem::path &path)
 
std::size_t listDir ()
 
std::string getOriginalDirectory () const
 
std::string getName (std::size_t position) const
 
std::string getPath (std::size_t position) const
 
ofFile getFile (std::size_t position, ofFile::Mode mode=ofFile::Reference, bool binary=true) const
 
const std::vector< ofFile > & getFiles () const
 
ofFile operator[] (std::size_t position) const
 
bool getShowHidden () const
 
void reset ()
 
void sort (const SortMode &mode=SORT_NATURAL)
 
void sortByDate ()
 
ofDirectory getSorted ()
 
std::size_t size () const
 
 OF_DEPRECATED_MSG ("Use size() instead.", int numFiles())
 
bool operator== (const ofDirectory &dir) const
 
bool operator!= (const ofDirectory &dir) const
 
bool operator< (const ofDirectory &dir) const
 
bool operator<= (const ofDirectory &dir) const
 
bool operator> (const ofDirectory &dir) const
 
bool operator>= (const ofDirectory &dir) const
 
 operator of::filesystem::path ()
 
 operator of::filesystem::path () const
 
std::vector< ofFile >::const_iterator begin () const
 
std::vector< ofFile >::const_iterator end () const
 
std::vector< ofFile >::const_reverse_iterator rbegin () const
 
std::vector< ofFile >::const_reverse_iterator rend () const
 

Static Public Member Functions

static bool createDirectory (const of::filesystem::path &dirPath, bool bRelativeToData=true, bool recursive=false)
 
static bool isDirectoryEmpty (const of::filesystem::path &dirPath, bool bRelativeToData=true)
 
static bool doesDirectoryExist (const of::filesystem::path &dirPath, bool bRelativeToData=true)
 
static bool removeDirectory (const of::filesystem::path &path, bool deleteIfNotEmpty, bool bRelativeToData=true)
 

Public Attributes

of::filesystem::path myDir
 
std::string originalDirectory
 
std::vector< std::string > extensions
 
std::vector< ofFilefiles
 
bool showHidden
 

Detailed Description

Path to a directory. Can be used to query file and directory contents.

Member Enumeration Documentation

◆ SortMode

Enumerator
SORT_FAST 
SORT_NATURAL 
SORT_BY_DATE 

Constructor & Destructor Documentation

◆ ofDirectory() [1/2]

ofDirectory::ofDirectory ( )

Create an ofDirectory instance

Does not refer to a specific directory until you either open or create a directory path.

◆ ofDirectory() [2/2]

ofDirectory::ofDirectory ( const of::filesystem::path &  path)

Create an ofDirectory instance and attempt to open the path.

Parameters
pathdirectory path

Member Function Documentation

◆ allowExt()

void ofDirectory::allowExt ( const std::string &  extension)

Allow a file extension when listing the contents the current directory path.

Setting an allowed extension enables a whitelist mode which only lists extensions which have been explicitly allowed.

Parameters
extensionfile type extension ie. "jpg", "png", "txt", etc

◆ begin()

vector< ofFile >::const_iterator ofDirectory::begin ( ) const

◆ canExecute()

bool ofDirectory::canExecute ( ) const

Check if the current path is executable.

Returns
true if executable

◆ canRead()

bool ofDirectory::canRead ( ) const

Check if the current path is readable.

Returns
true if readable

◆ canWrite()

bool ofDirectory::canWrite ( ) const

Check if the current path is writeable.

Returns
true if writable

◆ close()

void ofDirectory::close ( )

Close the currently open path.

◆ copyTo()

bool ofDirectory::copyTo ( const of::filesystem::path &  path,
bool  bRelativeToData = true,
bool  overwrite = false 
)

Copy the current file or directory path to a new path.

Copies relative to the data path & does not overwrite by default does not change the current path & assumes the new path is in the data directory.

Parameters
pathdestination file or directory path
bRelativeToDataset to false if you are working with paths that are not in the data directory
overwriteset to true if you want to overwrite the file or directory at the new path
Returns
true if the copy was successful

◆ create()

bool ofDirectory::create ( bool  recursive = false)

Create a directory at the current path.

Parameters
bRecursiveset to true to automatically create nested directories as required

◆ createDirectory()

bool ofDirectory::createDirectory ( const of::filesystem::path &  dirPath,
bool  bRelativeToData = true,
bool  recursive = false 
)
static

Create a directory at a given path.

Creates relative to the data path by default.

Parameters
dirPathdirectory path
bRelativeToDataset to false if you are working with paths that are not in the data directory
bRecursiveset to true to automatically create nested directories as required
Returns
true if directory was created successfully

◆ doesDirectoryExist()

bool ofDirectory::doesDirectoryExist ( const of::filesystem::path &  dirPath,
bool  bRelativeToData = true 
)
static

Check if a directory exists at a given path.

Assumes directory path is relative to the data path by default.

Parameters
dirPathdirectory path
bRelativeToDataset to false if you are working with paths that are not in the data directory
Returns
true if the directory exists

◆ end()

vector< ofFile >::const_iterator ofDirectory::end ( ) const

◆ exists()

bool ofDirectory::exists ( ) const

Check if a directory exists at the current path.

Returns
true if exists

◆ getAbsolutePath()

std::string ofDirectory::getAbsolutePath ( ) const

Get the absolute, full path of the directory, ie. "images" -> "/Users/mickey/of/apps/myApps/Donald/bin/data/images".

Returns
current path as an absolute path

◆ getFile()

ofFile ofDirectory::getFile ( std::size_t  position,
ofFile::Mode  mode = ofFile::Reference,
bool  binary = true 
) const

Open an ofFile instance using the path a given position in the directory contents list.

Opens as a binary file with readonly access by default.

Warning
Call listDir() before using this function or the directory contents list will be empty.
Exceptions
Throwsan out of bounds exception if position >= the number of listed directory contents.
Parameters
positionarray index in the directory contents list
modefile access mode depending on how you plan to use the file (read only, read write, etc)
binaryset to false if you are working with a text file & want lines split at endline characters automatically
Returns
ofFile instance

◆ getFiles()

const vector< ofFile > & ofDirectory::getFiles ( ) const

Get files and directories in the directory contents list.

Directory contents are automatically listed.

Returns
vector of files in the directory

◆ getName()

string ofDirectory::getName ( std::size_t  position) const

Get the filename at a given position in the directory contents list, ie. "duck.jpg".

Warning
Call listDir() before using this function or the directory contents list will be empty.
Exceptions
Throwsan out of bounds exception if position >= the number of listed directory contents.
Parameters
positionarray index in the directory contents list
Returns
file or directory name

◆ getOriginalDirectory()

string ofDirectory::getOriginalDirectory ( ) const
Returns
the current path

◆ getPath()

string ofDirectory::getPath ( std::size_t  position) const

Get the full path of the file or directory at a given position in the directory contents list.

Warning
Call listDir() before using this function or the directory contents list will be empty.
Exceptions
Throwsan out of bounds exception if position >= the number of listed directory contents.
Parameters
positionarray index in the directory contents list
Returns
file or directory name including the current path

◆ getShowHidden()

bool ofDirectory::getShowHidden ( ) const

Check whether hidden files & directories are included when listing files.

Mac & Linux denote hidden directories by prepending a period -> ".hello".

Returns
true if hidden files are shown

◆ getSorted()

ofDirectory ofDirectory::getSorted ( )

Get a sorted ofDirectory instance using the current path.

Returns
sorted ofDirectory instance

◆ isDirectory()

bool ofDirectory::isDirectory ( ) const

Check if the current path is indeed a directory and not a file.

Returns
true if a directory

◆ isDirectoryEmpty()

bool ofDirectory::isDirectoryEmpty ( const of::filesystem::path &  dirPath,
bool  bRelativeToData = true 
)
static

Check if a directory at a given path is empty.

Assumes directory path is relative to the data path by default.

Parameters
dirPathdirectory path
bRelativeToDataset to false if you are working with paths that are not in the data directory
Returns
true if the directory is empty aka contains no files or directories

◆ isHidden()

bool ofDirectory::isHidden ( ) const

Check if the current path is hidden.

Works on Mac & Linux which denote hidden directories by prepending a period -> ".hello", however always returns false on Windows.

Returns
true if hidden

◆ listDir() [1/2]

std::size_t ofDirectory::listDir ( )

Open and read the contents of the current directory.

Uses allowed extension whitelist to ignore unwanted file types if allowExt() has been called.

Returns
number of paths found

◆ listDir() [2/2]

std::size_t ofDirectory::listDir ( const of::filesystem::path &  path)

Open and read the contents of a directory.

Uses allowed extension whitelist to ignore unwanted file types if allowExt() has been called.

Parameters
pathdirectory path
Returns
number of paths found

◆ moveTo()

bool ofDirectory::moveTo ( const of::filesystem::path &  path,
bool  bRelativeToData = true,
bool  overwrite = false 
)

Move the current file or directory path to a new path.

Moves relative to the data path & does not overwrite by default does not change the current path & assumes the new path is in the data directory.

Parameters
pathdestination file or directory path
bRelativeToDataset to false if you are working with paths that are not in the data directory
overwriteset to true if you want to overwrite the file or directory at the new path
Returns
true if the copy was successful

◆ OF_DEPRECATED_MSG() [1/2]

ofDirectory::OF_DEPRECATED_MSG ( "Use ofDirectory::setWriteable(!flag)."  ,
void   setReadOnlybool flag 
)

◆ OF_DEPRECATED_MSG() [2/2]

ofDirectory::OF_DEPRECATED_MSG ( "Use size() instead."  ,
int   numFiles() 
)

◆ open()

void ofDirectory::open ( const of::filesystem::path &  path)

Open a directory path, clears the current file list.

Parameters
pathdirectory path

◆ openFromCWD()

void ofDirectory::openFromCWD ( const of::filesystem::path &  path)

Open a directory path relative to the current working directory without calling ofToDataPath internally, clears the current file list.

Parameters
pathdirectory path

◆ operator of::filesystem::path() [1/2]

ofDirectory::operator of::filesystem::path ( )
inline

◆ operator of::filesystem::path() [2/2]

ofDirectory::operator of::filesystem::path ( ) const
inline

◆ operator!=()

bool ofDirectory::operator!= ( const ofDirectory dir) const

◆ operator<()

bool ofDirectory::operator< ( const ofDirectory dir) const

◆ operator<=()

bool ofDirectory::operator<= ( const ofDirectory dir) const

◆ operator==()

bool ofDirectory::operator== ( const ofDirectory dir) const

◆ operator>()

bool ofDirectory::operator> ( const ofDirectory dir) const

◆ operator>=()

bool ofDirectory::operator>= ( const ofDirectory dir) const

◆ operator[]()

ofFile ofDirectory::operator[] ( std::size_t  position) const

Access directory contents via th array operator.

Warning
Call listDir() before using this function or the directory contents list will be empty.
Exceptions
Throwsan out of bounds exception if position >= the number of listed directory contents.
Parameters
positionarray index in the directory contents list
Returns
opened ofFile instance

◆ path()

std::string ofDirectory::path ( ) const

Get the current path.

Returns
current path

◆ rbegin()

vector< ofFile >::const_reverse_iterator ofDirectory::rbegin ( ) const

◆ remove()

bool ofDirectory::remove ( bool  recursive)

Removes the file or directory at the current path.

Does not remove non-empty directories by default.

Warning
Be careful! This deletes a file or folder. :)
Parameters
recursiveset to true to remove a non-empty directory and its contents
Returns
true if the path was removed successfully

◆ removeDirectory()

bool ofDirectory::removeDirectory ( const of::filesystem::path &  path,
bool  deleteIfNotEmpty,
bool  bRelativeToData = true 
)
static

remove a directory at a given path

Parameters
deleteIfNotEmptyset to true if you want to recursively delete the directory and its contents
bRelativeToDataset to false if you are working with paths that are not in the data directory
Returns
true if the path was removed successfully

◆ renameTo()

bool ofDirectory::renameTo ( const of::filesystem::path &  path,
bool  bRelativeToData = true,
bool  overwrite = false 
)

Rename the current file or directory path to a new path.

Renames relative to the data path & does not overwrite by default does not change the current path & assumes the new path is in the data directory.

Parameters
pathdestination file or directory path
bRelativeToDataset to false if you are working with paths that are not in the data folder
overwriteset to true if you want to overwrite the file or directory at the new path
Returns
true if the copy was successful

◆ rend()

vector< ofFile >::const_reverse_iterator ofDirectory::rend ( ) const

◆ reset()

void ofDirectory::reset ( )

Closes the directory.

This is for backwards compatibility with ofxDirList.

◆ setExecutable()

void ofDirectory::setExecutable ( bool  executable = true)

Set the executable flag of the current path.

Parameters
executableset to true to make path executable

◆ setReadable()

void ofDirectory::setReadable ( bool  readable = true)

Set the readable flag of the current path.

Parameters
readableset to true to make path readable

◆ setShowHidden()

void ofDirectory::setShowHidden ( bool  showHidden)

Show hidden files & directories when listing files?

Mac & Linux denote hidden directories by prepending a period -> ".hello".

Parameters
showHiddenset to true to show hidden files

◆ setWriteable()

void ofDirectory::setWriteable ( bool  writeable = true)

Set the writable flag of the current path.

Parameters
writableset to true to make path writable

◆ size()

std::size_t ofDirectory::size ( ) const

Get the number of paths in the current directory list.

Warning
Call listDir() before using this function or it will return 0 since the directory list will be empty.
Returns
number of paths

◆ sort()

void ofDirectory::sort ( const SortMode mode = SORT_NATURAL)

Sort the directory contents list alphabetically.

Warning
Call listDir() before using this function or there will be nothing to sort.
Parameters
SortModeoptions are SORT_FAST, SORT_NATURAL (default) or SORT_BY_DATE

◆ sortByDate()

void ofDirectory::sortByDate ( )

Sort the directory contents list by date.

Warning
Call listDir() before using this function or there will be nothing to sort.

Member Data Documentation

◆ extensions

std::vector<std::string> ofDirectory::extensions

◆ files

std::vector<ofFile> ofDirectory::files

◆ myDir

of::filesystem::path ofDirectory::myDir

◆ originalDirectory

std::string ofDirectory::originalDirectory

◆ showHidden

bool ofDirectory::showHidden

The documentation for this class was generated from the following files:
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/utils/ofFileUtils.h
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/utils/ofFileUtils.cpp