class methods
- addLeadingSlash()
- addTrailingSlash()
- createEnclosingDirectory()
- getAbsolutePath()
- getBaseName()
- getCurrentExeDir()
- getCurrentExePath()
- getCurrentWorkingDirectory()
- getEnclosingDirectory()
- getFileExt()
- getFileName()
- getPathForDirectory()
- getUserHomeDir()
- isAbsolute()
- join()
- makeRelative()
- removeExt()
- removeTrailingSlash()
Documentation from code comments
Static class for working with file path strings.
addLeadingSlash(...)
string ofFilePath::addLeadingSlash(const filesystem::path &path)
Documentation from code comments
Prepend path with a slash, ie. "images" -> "/images".
Parameters:
path file or directory path
Returns: slah + path
addTrailingSlash(...)
string ofFilePath::addTrailingSlash(const filesystem::path &path)
Documentation from code comments
Append path with a slash, ie. "images" -> "images/".
Parameters:
path directory path
Returns: path + slash
createEnclosingDirectory(...)
bool ofFilePath::createEnclosingDirectory(const filesystem::path &filePath, bool bRelativeToData=true, bool bRecursive=true)
Documentation from code comments
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 ofFilePath::getAbsolutePath(const filesystem::path &path, bool bRelativeToData=true)
Documentation from code comments
Get the absolute, full path for a given path, ie. "images" -> "/Users/mickey/of/apps/myApps/Donald/bin/data/images".
Parameters:
path file or directory 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: absolute path
getBaseName(...)
string ofFilePath::getBaseName(const filesystem::path &filePath)
string baseName = ofFilePath::getBaseName("/path/to/your-file.ext");
// baseName = "your-file"
Documentation from code comments
Get a file name without its extension, ie. "images/duck.jpg" -> "duck" and "images/some/folder" -> "folder"
Parameters:
filePath file path
Returns: basename
getCurrentExeDir()
string ofFilePath::getCurrentExeDir()
Documentation from code comments
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 ofFilePath::getCurrentExePath()
Documentation from code comments
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 ofFilePath::getCurrentWorkingDirectory()
Documentation from code comments
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 ofFilePath::getEnclosingDirectory(const filesystem::path &filePath, bool bRelativeToData=true)
Documentation from code comments
Get the enclosing parent directory of a path, ie. "images/duck.jpg" -> "images", assumes the path is in the data directory.
Parameters:
filePath 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: enclosing directory
getFileExt(...)
string ofFilePath::getFileExt(const filesystem::path &filename)
string ext = ofFilePath::getFileExt("/path/to/your-file.jpg");
// ext = "jpg"
Documentation from code comments
Get the extension of a filename, ie. "duck.jpg" -> "jpg".
Parameters:
filename file path
Returns: filename extension only
getFileName(...)
string ofFilePath::getFileName(const filesystem::path &filePath, bool bRelativeToData=true)
string fN = ofFilePath::getFileName("/path/to/your-file.ext");
// fN = "your-file.ext"
Documentation from code comments
Get the filename of a given path by stripping the parent directories ie. "images/duck.jpg" -> "duck.jpg", assumes the path is in the data folder.
Parameters:
filePath 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: filename
getPathForDirectory(...)
string ofFilePath::getPathForDirectory(const filesystem::path &path)
Documentation from code comments
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 ofFilePath::getUserHomeDir()
Documentation from code comments
Get the absolute path to the user's home directory.
Mac OSX: /Users/
Returns: home directory path
isAbsolute(...)
bool ofFilePath::isAbsolute(const filesystem::path &path)
Documentation from code comments
Check if a path is an absolute (aka a full path), ie. "images" -> false, "/Users/mickey/of/apps/myApps/Donald/bin/data/images" -> true.
Parameters:
path file or directory path
Returns: true if the path is an absolute path
join(...)
string ofFilePath::join(const filesystem::path &path1, const filesystem::path &path2)
Documentation from code comments
Create a single path by joining path1 & path2 using a slash, ie. "/hello/world" + "foo/bar" -> "/hello/world/foo/bar".
Parameters:
path1 left half of the path to join
path2 right half of the path to join
Returns: joined path
makeRelative(...)
string ofFilePath::makeRelative(const filesystem::path &from, const filesystem::path &to)
Documentation from code comments
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 ofFilePath::removeExt(const filesystem::path &filename)
Documentation from code comments
Remove extension from a filename, ie. "duck.jpg" ->"duck".
Parameters:
filename file path
Returns: filename without extension
removeTrailingSlash(...)
string ofFilePath::removeTrailingSlash(const filesystem::path &path)
Documentation from code comments
Remove a path's trailing slash (if found), ie. "images/" -> "images".
Parameters:
path directory path
Returns: path minus trailing slash
Last updated 星期二, 19 十一月 2024 17:25:49 UTC - 2537ee49f6d46d5fe98e408849448314fd1f180e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue