ofFilePath
addLeadingSlash( ... )
string addLeadingSlash(const filesystem::path &path)addTrailingSlash( ... )
string addTrailingSlash(const filesystem::path &path)createEnclosingDirectory( ... )
bool createEnclosingDirectory(const filesystem::path &filePath, bool bRelativeToData=true, bool bRecursive=true)Create the enclosing parent directory of a path, ie. "images" is the enclosing directory of "duck.jpg" = "images/duck.jpg".
Assumes the path is in the data folder & automatically creates nested directories as required.
Parameters:
bRecursive set to false to override automatically nested directory creation
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 enclosing directory was created
getAbsolutePath( ... )
string getAbsolutePath(const filesystem::path &path, bool bRelativeToData=true)getBaseName( ... )
string getBaseName(const filesystem::path &filePath)string baseName = ofFilePath::getBaseName("/path/to/your-file.ext");
// baseName = "your-file"
getCurrentExeDir( )
string getCurrentExeDir()Get the full path to the application's parent directory.
Windows & Linux: the application's parent directory Mac: the Contents/MacOS folder within the application's .app bundle
Returns: current executable directory
getCurrentExePath( )
string getCurrentExePath()Get the full path to the application's executable file.
Mac: the binary within the application's .app bundle Contents/MacOS dir Windows: the .exe Linux: the binary file itself
Returns: current executable path
getCurrentWorkingDirectory( )
string getCurrentWorkingDirectory()Get the full path to the app's current working directory.
This may be the app's parent directory or the location the app was launched from (aka on the commandline).
Warning: This location may change if you or a library calls the cd() std C function.
Returns: current working directory
getEnclosingDirectory( ... )
string getEnclosingDirectory(const filesystem::path &filePath, bool bRelativeToData=true)getFileExt( ... )
string getFileExt(const filesystem::path &filename)string ext = ofFilePath::getFileExt("/path/to/your-file.jpg");
// ext = "jpg"
getFileName( ... )
string getFileName(const filesystem::path &filePath, bool bRelativeToData=true)string fN = ofFilePath::getFileName("/path/to/your-file.ext");
// fN = "your-file.ext"
getPathForDirectory( ... )
string getPathForDirectory(const filesystem::path &path)Cleaned up a directory path by adding a trailing slash if needed.
For Windows-style path strings using "", a "" will be added. For Unix-style path strings using "/", a "/" will be added.
Parameters:
path directory path
Returns: cleaned path + trailing slash (if needed)
getUserHomeDir( )
string getUserHomeDir()isAbsolute( ... )
bool isAbsolute(const filesystem::path &path)join( ... )
string join(const filesystem::path &path1, const filesystem::path &path2)makeRelative( ... )
string makeRelative(const filesystem::path &from, const filesystem::path &to)Make one path relative to another, ie. the relative path of "images/felines/lions" to "images/felines/tigers" is "../tigers".
Parameters:
from starting path
to destination path
Returns: relative path
removeExt( ... )
string removeExt(const filesystem::path &filename)removeTrailingSlash( ... )
string removeTrailingSlash(const filesystem::path &path)