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 | Mode { Reference , ReadOnly , WriteOnly , ReadWrite , Append } |
file access mode More... | |
Public Member Functions | |
ofFile () | |
ofFile (const of::filesystem::path &path, Mode mode=ReadOnly, bool binary=true) | |
ofFile (const ofFile &mom) | |
ofFile & | operator= (const ofFile &mom) |
~ofFile () | |
bool | open (const of::filesystem::path &path, Mode mode=ReadOnly, bool binary=true) |
bool | openFromCWD (const of::filesystem::path &path, Mode mode=ReadOnly, bool binary=true) |
bool | changeMode (Mode mode, bool binary=true) |
void | close () |
Close a currently open file. | |
bool | create () |
bool | create (const of::filesystem::path &path) |
bool | exists () const |
std::string | path () const |
std::string | getExtension () const |
std::string | getFileName () const |
std::string | getBaseName () const |
std::string | getEnclosingDirectory () const |
std::string | getAbsolutePath () const |
bool | canRead () const |
bool | canWrite () const |
bool | canExecute () const |
bool | isFile () const |
bool | isLink () const |
bool | isDirectory () const |
bool | isDevice () const |
bool | isHidden () const |
void | setWriteable (bool writeable=true) |
Set the writable flag of the current path. | |
OF_DEPRECATED_MSG ("Use ofFile::setWriteable(!flag).", void setReadOnly(bool flag)) | |
void | setReadable (bool readable=true) |
Set the readable flag of the current path. | |
void | setExecutable (bool executable=true) |
Set the executable flag of the current path. | |
bool | copyTo (const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false) const |
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=false) |
uint64_t | getSize () const |
bool | operator== (const ofFile &file) const |
bool | operator!= (const ofFile &file) const |
bool | operator< (const ofFile &file) const |
bool | operator<= (const ofFile &file) const |
bool | operator> (const ofFile &file) const |
bool | operator>= (const ofFile &file) const |
ofBuffer | readToBuffer () |
bool | writeFromBuffer (const ofBuffer &buffer) |
std::filebuf * | getFileBuffer () const |
operator of::filesystem::path () | |
operator of::filesystem::path () const | |
Static Public Member Functions | |
static bool | copyFromTo (const of::filesystem::path &pathSrc, const of::filesystem::path &pathDst, bool bRelativeToData=true, bool overwrite=false) |
static bool | moveFromTo (const of::filesystem::path &pathSrc, const of::filesystem::path &pathDst, bool bRelativeToData=true, bool overwrite=false) |
static bool | doesFileExist (const of::filesystem::path &fPath, bool bRelativeToData=true) |
static bool | removeFile (const of::filesystem::path &path, bool bRelativeToData=true) |
Detailed Description
path to a file or directory
inherits from an fstream so you can read/write using the stream operators once a file path has been opened
Member Enumeration Documentation
◆ Mode
enum ofFile::Mode |
Constructor & Destructor Documentation
◆ ofFile() [1/3]
ofFile::ofFile | ( | ) |
Create an ofFile instance.
Does not refer to a specific file until you either open a file or create a file or directory path.
◆ ofFile() [2/3]
Create a new ofFile instance and attempt to open the path as a file.
Opens as a binary file with read only access by default.
- Parameters
-
path file path mode file access mode depending on how you plan to use the file (read only, read write, etc) binary set to false if you are working with a text file & want lines split at endline characters automatically
◆ ofFile() [3/3]
ofFile::ofFile | ( | const ofFile & | mom | ) |
Create a new file path using the same path & settings of another file.
- Parameters
-
mom ofFile instance source
◆ ~ofFile()
ofFile::~ofFile | ( | ) |
Member Function Documentation
◆ canExecute()
bool ofFile::canExecute | ( | ) | const |
Check if the current path is executable.
- Returns
- true if executable
◆ canRead()
bool ofFile::canRead | ( | ) | const |
Check if the current path is readable.
- Returns
- true if readable
◆ canWrite()
bool ofFile::canWrite | ( | ) | const |
Check if the current path is writable.
- Returns
- true if writable
◆ changeMode()
bool ofFile::changeMode | ( | Mode | mode, |
bool | binary = true |
||
) |
Reopen the current file path with a different access mode.
- Parameters
-
mode file access mode depending on how you plan to use the file (read only, read write, etc) binary set to false if you are reading a text file & want lines split at endline characters automatically
- Returns
- true if the file was reopened with the new access mode(s).
◆ close()
void ofFile::close | ( | ) |
Close a currently open file.
◆ copyFromTo()
|
static |
Copy source path to destination path.
Copies relative to the data path & does not overwrite by default assumes the source & destination path is in the data directory.
- Parameters
-
pathSrc source file or directory path pathDst destination file or directory path bRelativeToData set to false if you are working with paths that are not in the data directory overwrite set to true if you want to overwrite the file or directory at the new path
- Returns
- true if the copy was successful
◆ copyTo()
bool ofFile::copyTo | ( | const of::filesystem::path & | path, |
bool | bRelativeToData = true , |
||
bool | overwrite = false |
||
) | const |
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 folder.
- Parameters
-
path destination file or directory path bRelativeToData set to false if you are working with paths that are not in the data folder overwrite set to true if you want to overwrite the file or directory at the new path
- Returns
- true if the copy was successful
◆ create() [1/2]
bool ofFile::create | ( | ) |
Create a file at the current path.
Creates as a write only binary file by default.
- Returns
- true if the file was created
◆ create() [2/2]
bool ofFile::create | ( | const of::filesystem::path & | path | ) |
Create a file at a given path.
Creates as a write only binary file by default.
- Parameters
-
path file path
- Returns
- true if the file was created
◆ doesFileExist()
|
static |
Check if a file or directory exists at a given path.
- Parameters
-
fPath file path bRelativeToData set to false if you are working with paths that are not in the data folder and want the direct path without relative "../../"
- Returns
- true if a file or directory exists
◆ exists()
bool ofFile::exists | ( | ) | const |
Check if a file exists at the current path.
- Returns
- true if the file exists
◆ getAbsolutePath()
std::string ofFile::getAbsolutePath | ( | ) | const |
\biref Get the absolute, full path of the file, ie. "images" -> "/Users/mickey/of/apps/myApps/Donald/bin/data/images".
- Returns
- current path as an absolute path
◆ getBaseName()
string ofFile::getBaseName | ( | ) | const |
\biref Get the current path without its last component, ie. "images/duck.jpg" -> "images" and "images/some/folder" -> "images/some".
- Returns
- current path basename
◆ getEnclosingDirectory()
std::string ofFile::getEnclosingDirectory | ( | ) | const |
Get the enclosing parent directory of a path, ie. "images/duck.jpg" -> "images", assumes the path is in the data directory.
- Returns
- current path's enclosing directory
◆ getExtension()
string ofFile::getExtension | ( | ) | const |
Get the current path without its extension, ie. "duck.jpg" ->"duck".
- Returns
- current path file extension
◆ getFileBuffer()
std::filebuf * ofFile::getFileBuffer | ( | ) | const |
Read the entire contents of the currently opened file into an output stream.
This is basically an easy to use equivalent to rdbuf(): ie. ofLogNotice() << file.getFileBuffer(); write_file << file.getFileBuffer();
- Returns
- output stream
◆ getFileName()
string ofFile::getFileName | ( | ) | const |
Get the filename of the current path by stripping the parent directories, ie. "images/duck.jpg" -> "duck.jpg".
- Returns
- current path filename
◆ getSize()
uint64_t ofFile::getSize | ( | ) | const |
get the size of the file at the current file path
- Returns
- size in bytes
◆ isDevice()
bool ofFile::isDevice | ( | ) | const |
Check if the current path is a device file.
Works on Mac & Linux which can represent devices as files, however always returns false on Windows.
- Returns
- true if a device file
◆ isDirectory()
bool ofFile::isDirectory | ( | ) | const |
Check if the current path is a directory and not a file.
- Returns
- true if a directory
◆ isFile()
bool ofFile::isFile | ( | ) | const |
Check if the current path is a file and not a directory.
- Returns
- true if a file
◆ isHidden()
bool ofFile::isHidden | ( | ) | const |
Check if the current path is hidden.
Works on Mac & Linux which denote hidden files by prepending a period to the filename -> ".hello", however always returns false on Windows.
- Returns
- true if hidden
◆ isLink()
bool ofFile::isLink | ( | ) | const |
Check if the current path is a system link to another file or directory.
- Returns
- true if a system link
◆ moveFromTo()
|
static |
Move source path to destination path.
Moves relative to the data path & does not overwrite by default assumes the source & destination path is in the data directory.
- Parameters
-
pathSrc source file or directory path pathDst destination file or directory path bRelativeToData set to false if you are working with paths that are not in the data folder overwrite set to true if you want to overwrite the file or directory at the new path
- Warning
- be careful with slashes here, appending a slash when moving a folder may cause mad headaches in OSX
- Returns
- true if the move was successful
◆ moveTo()
bool ofFile::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 folder.
- Parameters
-
path destination file or directory path bRelativeToData set to false if you are working with paths that are not in the data folder overwrite set 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()
ofFile::OF_DEPRECATED_MSG | ( | "Use ofFile::setWriteable(!flag)." | , |
void | setReadOnlybool flag | ||
) |
◆ open()
Open the path as a file.
Opens as a text file with read only access by default.
- Parameters
-
path file path mode file access mode depending on how you plan to use the file (read only, read write, etc) binary set to false if you are reading a text file & want lines split at endline characters automatically
- Returns
- true if the path was opened
◆ openFromCWD()
bool ofFile::openFromCWD | ( | const of::filesystem::path & | path, |
Mode | mode = ReadOnly , |
||
bool | binary = true |
||
) |
Open the path as a file.
Opens as a text file with read only access by default from the current working directory without internally calling ofToDataPath.
- Parameters
-
path file path mode file access mode depending on how you plan to use the file (read only, read write, etc) binary set to false if you are reading a text file & want lines split at endline characters automatically
- Returns
- true if the path was opened
◆ operator of::filesystem::path() [1/2]
|
inline |
◆ operator of::filesystem::path() [2/2]
|
inline |
◆ operator!=()
bool ofFile::operator!= | ( | const ofFile & | file | ) | const |
◆ operator<()
bool ofFile::operator< | ( | const ofFile & | file | ) | const |
◆ operator<=()
bool ofFile::operator<= | ( | const ofFile & | file | ) | const |
◆ operator=()
◆ operator==()
bool ofFile::operator== | ( | const ofFile & | file | ) | const |
◆ operator>()
bool ofFile::operator> | ( | const ofFile & | file | ) | const |
◆ operator>=()
bool ofFile::operator>= | ( | const ofFile & | file | ) | const |
◆ path()
std::string ofFile::path | ( | ) | const |
Get the current path.
- Returns
- current path
◆ readToBuffer()
ofBuffer ofFile::readToBuffer | ( | ) |
Read the contents of a file at the current path into a buffer.
- Returns
- buffer with file contents
◆ remove()
bool ofFile::remove | ( | bool | recursive = false | ) |
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
-
recursive set to true to remove a non-empty directory and its contents
- Returns
- true if the path was removed successfully
◆ removeFile()
|
static |
Remove a file or directory at a given path.
- Parameters
-
bRelativeToData set to false if you are working with paths that are not in the data folder and want the direct path without relative "../../"
- Returns
- true if the path was removed successfully
◆ renameTo()
bool ofFile::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 folder.
- Parameters
-
path destination file or directory path bRelativeToData set to false if you are working with paths that are not in the data folder overwrite set to true if you want to overwrite the file or directory at the new path
- Returns
- true if the copy was successful
◆ setExecutable()
void ofFile::setExecutable | ( | bool | executable = true | ) |
Set the executable flag of the current path.
◆ setReadable()
void ofFile::setReadable | ( | bool | readable = true | ) |
Set the readable flag of the current path.
◆ setWriteable()
void ofFile::setWriteable | ( | bool | writeable = true | ) |
Set the writable flag of the current path.
◆ writeFromBuffer()
bool ofFile::writeFromBuffer | ( | const ofBuffer & | buffer | ) |
Write the contents of a buffer into a file at the current path.
- Parameters
-
buffer source byte buffer
- Returns
- true if buffer's contents written successfully
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