Open Lighting Architecture  Latest Git
Functions | Variables
ola::file Namespace Reference

Detailed Description

File helper functions.

Functions

string ConvertPathSeparators (const std::string &path)
 Convert all separators in a path to the OS's version. More...
 
string JoinPaths (const std::string &first, const std::string &second)
 Join two parts of a path. More...
 
bool FindMatchingFiles (const std::string &directory, const std::string &prefix, std::vector< std::string > *files)
 Find all files in a directory that match the given prefix. More...
 
bool FindMatchingFiles (const std::string &directory, const std::vector< std::string > &prefixes, std::vector< std::string > *files)
 Find all files in a directory that match any of the prefixes. More...
 
bool ListDirectory (const std::string &directory, std::vector< std::string > *files)
 Get a list of all files in a directory. More...
 
string FilenameFromPathOrDefault (const std::string &path, const std::string &default_value)
 Convert a path to a filename. More...
 
string FilenameFromPathOrPath (const std::string &path)
 Convert a path to a filename (this variant is good for switching based on executable names) More...
 
string FilenameFromPath (const std::string &path)
 Convert a path to a filename. More...
 

Variables

const char PATH_SEPARATOR = '/'
 

Function Documentation

◆ ConvertPathSeparators()

std::string ola::file::ConvertPathSeparators ( const std::string &  path)

Convert all separators in a path to the OS's version.

Parameters
paththe path to convert
Returns
the path with all path separators switched to the OS's version

◆ FilenameFromPath()

std::string ola::file::FilenameFromPath ( const std::string &  path)

Convert a path to a filename.

Parameters
patha full path to a file
Returns
the filename (basename) part of the path or "" if it can't be found

◆ FilenameFromPathOrDefault()

std::string ola::file::FilenameFromPathOrDefault ( const std::string &  path,
const std::string &  default_value 
)

Convert a path to a filename.

Parameters
patha full path to a file
default_valuewhat to return if the path can't be found
Returns
the filename (basename) part of the path or default if it can't be found

◆ FilenameFromPathOrPath()

std::string ola::file::FilenameFromPathOrPath ( const std::string &  path)

Convert a path to a filename (this variant is good for switching based on executable names)

Parameters
patha full path to a file
Returns
the filename (basename) part of the path or the whole path if it can't be found

◆ FindMatchingFiles() [1/2]

bool ola::file::FindMatchingFiles ( const std::string &  directory,
const std::string &  prefix,
std::vector< std::string > *  files 
)

Find all files in a directory that match the given prefix.

Parameters
[in]directorythe directory to look in
[in]prefixthe prefix to match on
[out]filesa pointer to a vector with the absolute path of the matching files.
Returns
false if there was an error, true otherwise.

◆ FindMatchingFiles() [2/2]

bool ola::file::FindMatchingFiles ( const std::string &  directory,
const std::vector< std::string > &  prefixes,
std::vector< std::string > *  files 
)

Find all files in a directory that match any of the prefixes.

Parameters
[in]directorythe directory to look in
[in]prefixesthe prefixes to match on
[out]filesa pointer to a vector with the absolute path of the matching files.
Returns
false if there was an error, true otherwise.

◆ JoinPaths()

std::string ola::file::JoinPaths ( const std::string &  first,
const std::string &  second 
)

Join two parts of a path.

Parameters
firstThe first part of the path.
secondThe second part of the path.
Returns
The concatenated path, with the separator if required.

◆ ListDirectory()

bool ola::file::ListDirectory ( const std::string &  directory,
std::vector< std::string > *  files 
)

Get a list of all files in a directory.

Entries in

Parameters
fileswill contain the full path to the file.
[in]directorythe directory to list
[out]filesa pointer to a string vector that will receive file paths
Returns
false if there was an error, true otherwise.