Folders¶
A set of functions to manipulate paths and create folders.
-
std::string
mirheo
::
createStrZeroPadded
(long long i, int zeroPadding = 5)¶ Create a string representing an integer with 0 padding.
If
zeroPadding
is too small, this method will die. Example:createStrZeroPadded(42, 5)
gives “00042”- Return
- the string representation of
i
with padded zeros - Parameters
i
: The integer to print (must non negative)zeroPadding
: The total number of characters
-
std::vector<std::string>
mirheo
::
splitByDelim
(std::string str, char delim = ',')¶ Split a string according to a delimiter character.
e.g.
splitByDelim
(“string_to_split”, ‘_’) -> {“string”, “to”, “split”}- Return
- The list of substrings (without the delimiter)
- Parameters
str
: The input sequence of charactersdelim
: The delimiter
-
std::string
mirheo
::
makePath
(std::string path)¶ append ‘/’ at the end of
path
if it doesn t have it already- Return
- The path with a trailing separator
- Parameters
path
: The path to work with
-
std::string
mirheo
::
getParentPath
(std::string path)¶ Get the parent folder of the given filename.
If the input is a path (it ends with a ‘/’), the output is the same as the input. If the input is just a filename with no ‘/’, this function returns an empty string.
- Return
- The parent folder.
- Parameters
path
: The filename containing a path
-
std::string
mirheo
::
getBaseName
(std::string path)¶ remove the path from the given filename.
- Return
- the filename only without any prepended folder
- Parameters
path
: The filename with full relative or absolute path
-
std::string
mirheo
::
joinPaths
(const std::string &A, const std::string &B)¶ Concatenate two paths A and B.
- Return
- A/B Adds a ‘/’ between
A
andB
ifA
is non-empty and if it doesn’t already end with ‘/’. - Parameters
A
: first part of the full pathB
: last part of the full path
-
bool
mirheo
::
createFoldersCollective
(const MPI_Comm &comm, std::string path)¶ Create a folder.
The operation is collective. This means that all ranks in the
comm
must call it. The returned value is accessible by all ranks.- Return
true
if the operation was successful,false
otherwise- Parameters
comm
: The communicator used to decide which rank creates the folderpath
: the folder to create