Jetson Inference
DNN Vision Library
|
Functions for listing files in directories and manipulating file paths. More...
Enumerations | |
enum | fileTypes { FILE_MISSING = 0, FILE_REGULAR = (1 << 0), FILE_DIR = (1 << 1), FILE_LINK = (1 << 2), FILE_CHAR = (1 << 3), FILE_BLOCK = (1 << 4), FILE_FIFO = (1 << 5), FILE_SOCKET = (1 << 6) } |
File types. More... | |
Functions | |
std::string | absolutePath (const std::string &relative_path) |
Given a relative path, resolve the absolute path using the working directory. More... | |
std::string | locateFile (const std::string &path) |
Locate a file from common system locations. More... | |
std::string | locateFile (const std::string &path, std::vector< std::string > &locations) |
Locate a file from a set of locations provided by the user, in addition to common system locations such as "/opt" and "/usr/local". More... | |
std::string | readFile (const std::string &path) |
Read a text file into a string. More... | |
std::string | pathJoin (const std::string &a, const std::string &b) |
Join two paths, and properly include a path separator (/ ) as needed. More... | |
std::string | pathDir (const std::string &path) |
Return the parent directory of the specified path, removing the filename and extension. More... | |
std::string | pathFilename (const std::string &path) |
Return the filename from the path, including the file extension. More... | |
std::pair< std::string, std::string > | splitPath (const std::string &path) |
Split a path into directory and filename components. More... | |
bool | listDir (const std::string &path, std::vector< std::string > &list, uint32_t mask=0) |
Return a sorted list of the files in the specified directory. More... | |
bool | fileExists (const std::string &path, uint32_t mask=0) |
Return the directory /** Verify path and return true if the file exists. More... | |
bool | fileIsType (const std::string &path, uint32_t mask) |
Return true if the file is one of the types in the fileTypes mask. More... | |
uint32_t | fileType (const std::string &path) |
Return the file type, or FILE_MISSING if it doesn't exist. More... | |
size_t | fileSize (const std::string &path) |
Return the size (in bytes) of the specified file. More... | |
std::string | fileExtension (const std::string &path) |
Extract the file extension from the path. More... | |
bool | fileHasExtension (const std::string &path, const std::string &extension) |
Return true if the file has the given extension, otherwise false. More... | |
bool | fileHasExtension (const std::string &path, const std::vector< std::string > &extensions) |
Return true if the file has one of the given extensions, otherwise false. More... | |
bool | fileHasExtension (const std::string &path, const char **extensions) |
Return true if the file has one of the given extensions, otherwise false. More... | |
std::string | fileRemoveExtension (const std::string &filename) |
Return the input string with the file extension removed For example, fileRemoveExtension("~/workspace/somefile.xml") would return ~/user/somefile . More... | |
std::string | fileChangeExtension (const std::string &filename, const std::string &newExtension) |
Return the input string with a changed file extension For example, fileChangeExtension("~/workspace/somefile.xml", "zip") would return ~/user/somefile.zip . More... | |
Functions for listing files in directories and manipulating file paths.
enum fileTypes |
std::string absolutePath | ( | const std::string & | relative_path | ) |
Given a relative path, resolve the absolute path using the working directory.
For example, if the current working directory /home/user/
and absolutePath("resources/example")
is called, then this function would return the path /home/user/resources/example
.
If the path is already an absolute path (i.e. it begins with /
or ~/
) then this function will be ignored and the path will be returned as-is.
std::string fileChangeExtension | ( | const std::string & | filename, |
const std::string & | newExtension | ||
) |
Return the input string with a changed file extension For example, fileChangeExtension("~/workspace/somefile.xml", "zip")
would return ~/user/somefile.zip
.
bool fileExists | ( | const std::string & | path, |
uint32_t | mask = 0 |
||
) |
Return the directory /** Verify path and return true if the file exists.
mask | filter by file type (by default, any file including directories will be checked). The mask should consist of fileTypes OR'd together (e.g. FILE_REGULAR|FILE_DIR ). |
std::string fileExtension | ( | const std::string & | path | ) |
Extract the file extension from the path.
This function will return all contents of the path to the right of the right-most ‘’.'` The extension will be returned in all lowercase characters.
bool fileHasExtension | ( | const std::string & | path, |
const char ** | extensions | ||
) |
Return true if the file has one of the given extensions, otherwise false.
For example, fileHasExtension("image.jpg", {"jpg", "jpeg", NULL})
would return true.
extensions | list of extensions, should end with NULL sentinel. |
bool fileHasExtension | ( | const std::string & | path, |
const std::string & | extension | ||
) |
Return true if the file has the given extension, otherwise false.
For example, fileHasExtension("~/workspace/image.jpg", "jpg")
would return true.
bool fileHasExtension | ( | const std::string & | path, |
const std::vector< std::string > & | extensions | ||
) |
Return true if the file has one of the given extensions, otherwise false.
bool fileIsType | ( | const std::string & | path, |
uint32_t | mask | ||
) |
std::string fileRemoveExtension | ( | const std::string & | filename | ) |
Return the input string with the file extension removed For example, fileRemoveExtension("~/workspace/somefile.xml")
would return ~/user/somefile
.
size_t fileSize | ( | const std::string & | path | ) |
Return the size (in bytes) of the specified file.
path | the path of the file |
uint32_t fileType | ( | const std::string & | path | ) |
Return the file type, or FILE_MISSING if it doesn't exist.
bool listDir | ( | const std::string & | path, |
std::vector< std::string > & | list, | ||
uint32_t | mask = 0 |
||
) |
Return a sorted list of the files in the specified directory.
listDir() will glob files from the specified path, and filter against wildcard characters including *
and ?
. For example, valid paths would include ~/workspace
, ~/workspace/*.jpg
, ect.
path | the path of the directory (may include wildcard characters) | |
[out] | list | the alphanumerically sorted output list of the files in the directory |
mask | filter by file type (by default, any file including directories will be included). The mask should consist of fileTypes OR'd together (e.g. FILE_REGULAR|FILE_DIR ). |
std::string locateFile | ( | const std::string & | path | ) |
Locate a file from common system locations.
First, this function will check if the file exists at the path provided, and if not it will check for the existance of the file in common system locations such as "/opt", "/usr/local", and "/usr/local/bin".
std::string locateFile | ( | const std::string & | path, |
std::vector< std::string > & | locations | ||
) |
Locate a file from a set of locations provided by the user, in addition to common system locations such as "/opt" and "/usr/local".
std::string pathDir | ( | const std::string & | path | ) |
Return the parent directory of the specified path, removing the filename and extension.
For example, pathDir("~/workspace/somefile.xml")
would return ~/workspace/
std::string pathFilename | ( | const std::string & | path | ) |
Return the filename from the path, including the file extension.
std::string pathJoin | ( | const std::string & | a, |
const std::string & | b | ||
) |
Join two paths, and properly include a path separator (/
) as needed.
For example, 'pathJoin("~/workspace", "somefile.xml")would return
~/workspace/somefile.xml`.
std::string readFile | ( | const std::string & | path | ) |
Read a text file into a string.
It's assumed that the file is text, and that it is of a managegable size (otherwise you should use buffering and read it line-by-line)
std::pair<std::string, std::string> splitPath | ( | const std::string & | path | ) |
Split a path into directory and filename components.
The directory will be returned first in the pair, and the filename second.