- english
- /
- japanese
methods
- allowExt()
- canExecute()
- canRead()
- canWrite()
- close()
- copyTo()
- create()
- createDirectory()
- doesDirectoryExist()
- exists()
- getAbsolutePath()
- getFile()
- getFiles()
- getName()
- getOriginalDirectory()
- getPath()
- getPocoFile()
- getShowHidden()
- isDirectory()
- isDirectoryEmpty()
- isHidden()
- listDir()
- moveTo()
- numFiles()
- open()
- operator!=()
- operator<()
- operator<=()
- operator==()
- operator>()
- operator>=()
- operator[]()
- path()
- remove()
- removeDirectory()
- renameTo()
- reset()
- setExecutable()
- setReadOnly()
- setShowHidden()
- setWriteable()
- size()
- sort()
ofDirectory is a class for reading and manipulating directories on the file system through openFrameworks.
Here is a common way to use it:
//some path, may be absolute or relative to bin/data
string path = "/my/path/file";
ofDirectory dir(path);
//only show png files
dir.allowExt("png");
//populate the directory object
dir.listDir();
//go through and print out all the paths
for(int i = 0; i < dir.numFiles(); i++){
ofLogNotice(dir.getPath(i));
}
allowExt(...)
void ofDirectory::allowExt(string extension)
Adds an allowed extension to the list of filters when listing directories. Use this to set any number of filters before calling listDir().
For example if you wanted to only get images in a directory, you may set several filters:
string path = "/path/to/images";
ofDirectory dir(path);
dir.allowExt("png");
dir.allowExt("jpg");
dir.allowExt("gif");
dir.listDir();
canExecute()
bool ofDirectory::canExecute()
Returns true if the current directory is executable. An executable directory can be entered into with command such as cd.
copyTo(...)
bool ofDirectory::copyTo(string path, bool bRelativeToData=true, bool overwrite=false)
Copies the directory into path. If bRelativeToData is set to false then path should be absolute. If overwrite is set to true any existing files with the same name will be overwritten by the copy.
create(...)
bool ofDirectory::create(bool recursive=false)
Creates the directory if it doesn't exist already. A common reason to use create is to ensure that you are able to write files to a known path, like so
string path = "/path/to/file";
ofDirectory dir(path);
if(!dir.exists()){
dir.create(true);
}
//now you can be sure that path exists
The recursive boolean flag will indicate if you'd like to create directories all the directories required to reach the given path. In our example, if "/path/to" didn't already exist, the call to create() would also create these. If recursive were set to false, the directory would not be created.
createDirectory(...)
bool ofDirectory::createDirectory(string dirPath, bool bRelativeToData=true, bool recursive=false)
Static method to create a directory at a given path.
doesDirectoryExist(...)
bool ofDirectory::doesDirectoryExist(string dirPath, bool bRelativeToData=true)
Returns true if the directory at dirPath exists.
exists()
bool ofDirectory::exists()
Returns true if the open directory exists. Great to be used in conjunction with ofDirectory::create()
getFile(...)
ofFile ofDirectory::getFile(unsigned int position, ofFile)
Opens and returns an ofFile object at position. Mode determines how you may interact with the file, the options being: Reference,ofFile::ReadOnly, ofFile::WriteOnly, ofFile::ReadWrite, ofFile::Append
getFile(...)
ofFile ofDirectory::getFile(unsigned int position, ofFile::Mode mode=ofFile::Reference, bool binary=false)
getFiles()
ofFile ofDirectory::getFiles()
Returns a vector of ofFile objects populated by a prior call to listDir(). The files are opened in ofFile::Reference mode.
getName(...)
string ofDirectory::getName(unsigned int position)
Returns the file name,(eg "mypicture.png") with extension but not the enclosing path at a given index. Position must be less than the result of numFiles().
getPath(...)
string ofDirectory::getPath(unsigned int position)
Returns the absolute path,(eg "/path/to/files/mypicture.png"). Position must be less than the result of size().
getShowHidden()
bool ofDirectory::getShowHidden()
Returns if hidden files are set to be shown or not.
isDirectory()
bool ofDirectory::isDirectory()
Returns true if the given path is actually a directory.
isDirectoryEmpty(...)
bool ofDirectory::isDirectoryEmpty(string dirPath, bool bRelativeToData=true)
Returns true if the directory at dirPath is empty.
listDir(...)
int ofDirectory::listDir(string path)
Opens and populates the directory with files. Returns the number of files found.
listDir()
int ofDirectory::listDir()
Populates the directory with files. Call this after opening a directory and setting filters. After this call, size(), getPath(position), and getName(position) can be used to access the contents of the directory.
moveTo(...)
bool ofDirectory::moveTo(string path, bool bRelativeToData=true, bool overwrite=false)
Moves the directory into another directory at path. If bRelativeToData is set to false then path should be absolute. If overwrite is set to true any existing files with the same name will be overwritten by the move.
open(...)
void ofDirectory::open(string path)
Opens a path. At this point you can see if the directory exists by calling exists() but the contents of the path are not accessible until listDir() is called.
operator!=(...)
bool ofDirectory::operator!=(const ofDirectory &dir)
Returns true if this directory and another have different paths.
operator<(...)
bool ofDirectory::operator<(const ofDirectory &dir)
Returns true if the right hand side directory is alphabetically after the left hand side directory.
operator<=(...)
bool ofDirectory::operator<=(const ofDirectory &dir)
Returns true if the right hand side directory is alphabetically after or equal to the left hand side directory.
operator==(...)
bool ofDirectory::operator==(const ofDirectory &dir)
Returns true if this directory and another have the same path.
operator>(...)
bool ofDirectory::operator>(const ofDirectory &dir)
Returns true if the left hand side directory is alphabetically after the right hand side directory.
operator>=(...)
bool ofDirectory::operator>=(const ofDirectory &dir)
Returns true if the left hand side directory is alphabetically after or equal to the right hand side directory;
operator[](...)
Operator for accessing files with array notation syntax. Call is equivalent to ofFile::getFile(position).
remove(...)
bool ofDirectory::remove(bool recursive)
Deletes the directory. If recursive is set to false and this directory contains others the remove will fail.
removeDirectory(...)
bool ofDirectory::removeDirectory(string path, bool deleteIfNotEmpty, bool bRelativeToData=true)
Removes a directory. If deleteIfNotEmpty is set to false and the directory contains files the call will fail.
renameTo(...)
bool ofDirectory::renameTo(string path, bool bRelativeToData=true, bool overwrite=false)
Renames the directory to the path path. If bRelativeToData is set to false then path should be absolute. If overwrite is set to true any existing files with the same name will be overwritten by the rename.
setExecutable(...)
void ofDirectory::setExecutable(bool executable)
Enables or disables execution on the current open directory. If the directory is executable then it can be entered through commands such as cd.
setReadOnly(...)
void ofDirectory::setReadOnly(bool readable)
Enables or disables readable on the current open directory.
setShowHidden(...)
void ofDirectory::setShowHidden(bool showHidden)
Sets whether or not the call to listDir() will return hidden files.
setWriteable(...)
void ofDirectory::setWriteable(bool writeable)
Enables or disables writeable on the current open directory.
size()
unsigned int ofDirectory::size()
Returns the number of files contained within the directory. Set after listDir() is called.
Last updated
Thursday, 16 May 2013 14:01:09 UTC
-
cbf0910627a25e6153f2452833c5313fe6067059

