AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::utilities::filesystem Namespace Reference

Functions

std::string getCWD ()
 Returns the current working directory within the file system. More...
 
int changeCWD (const std::string &dirName)
 Changes the current working directory within the file system. More...
 
bool pathExists (const std::string &fileName)
 Checks if the path pointed to by fileName exists. More...
 
std::string joinPath (const std::string &fileDir, const std::string &fileName, const std::string &separator="/")
 Joins two strings with the given separator char. More...
 
int makeDirsForPath (const std::string &path)
 Make directories for a given path string. More...
 
void getDirName (std::string &dir, const std::string &path)
 Get directory name from a path that contains a file name. More...
 
int removeFile (const std::string &filename)
 Remove the specified file. More...
 

Function Documentation

◆ getCWD()

std::string axom::utilities::filesystem::getCWD ( )

Returns the current working directory within the file system.

Returns
path of cwd if found, else, returns "./"

◆ changeCWD()

int axom::utilities::filesystem::changeCWD ( const std::string &  dirName)

Changes the current working directory within the file system.

Parameters
[in]dirNamean absolute or relative directory path
Returns
Status code 0 for success, non-zero otherwise

◆ pathExists()

bool axom::utilities::filesystem::pathExists ( const std::string &  fileName)

Checks if the path pointed to by fileName exists.

Parameters
[in]fileNamename of the file to check
Returns
true if file system contains a file named fileName, false otherwise

◆ joinPath()

std::string axom::utilities::filesystem::joinPath ( const std::string &  fileDir,
const std::string &  fileName,
const std::string &  separator = "/" 
)

Joins two strings with the given separator char.

Parameters
[in]fileDirThe directory of the file
[in]fileNameThe name of the file
[in]separatora single character to seperate the two strings
Note
fileDir can be the empty string
fileName can include directories (e.g. a/b/c.txt), but should not be an absolute path f a non-empty fileDir is supplied.
Returns
The concatenated string: fileDir + fileName, with separator in between, if necessary
Note
Example1: joinPath("abc", "def") -> "abc/def"
Example2: joinPath("abc/", "def") -> "abc/def"
Example3: joinPath("abc/", "def/ghi") -> "abc/def/ghi"

◆ makeDirsForPath()

int axom::utilities::filesystem::makeDirsForPath ( const std::string &  path)

Make directories for a given path string.

Parameters
[in]pathstring representing an absolute or relative directory path

Everything in the path is assumed to be intended to be a directory. If a directory in the path already exists, nothing is done. If a directory doesn't exist, it is created.

◆ getDirName()

void axom::utilities::filesystem::getDirName ( std::string &  dir,
const std::string &  path 
)

Get directory name from a path that contains a file name.

Parameters
[out]dira directory path formed by removing the file name from the input path
[in]pathan absolute or relative directory/file path

This function assumes that the input path has a file name at the end, and it removes that file name, leaving a string containing only a directory path.

For example, if the path string is "abc/def/ghi/file.txt", the output dir string will be "abc/def/ghi". If the path string is "file.txt", the output dir string will be "" (the empty string).

◆ removeFile()

int axom::utilities::filesystem::removeFile ( const std::string &  filename)

Remove the specified file.

Parameters
filenameThe name of the file.
Returns
0 on success, -1 on failure. errno can obtain more information about the failure.
Note
On Windows, this function calls _unlink() and will fail if there are any open file handles to the specified file. On Linux, this function calls unlink() and will succeed even if there are open file handles to the specified file.