Bifrost SDK
Bifrost SDK documentation
Bifrost File Utilities

Functions

bool Bifrost::FileUtils::isAbsolute (Amino::StringView path)
 Checks if a path is absolute. More...
 
bool Bifrost::FileUtils::createDirectories (Amino::StringView path, Amino::String *errorMessage=nullptr)
 Creates the directories in path that do not exist. More...
 
bool Bifrost::FileUtils::currentPath (Amino::String &currentPath, Amino::String *errorMessage=nullptr)
 Returns the current path. More...
 
Amino::String Bifrost::FileUtils::extractParentPath (Amino::StringView path)
 Returns the parent path of path. The input is first processed by makePreferred. Then the extraction follows C++17 std::filesystem. More...
 
Amino::String Bifrost::FileUtils::makePreferred (Amino::StringView path)
 Convert directory separator characters in the given string to the operating system's preferred character. (For unix systems this is a forward slash, and for Windows, a backslash) More...
 
Amino::String Bifrost::FileUtils::filePath (Amino::StringView directory, Amino::StringView filename)
 Create a file path from a directory and an filename in an operating system / independent way. More...
 
Amino::String Bifrost::FileUtils::filename (Amino::StringView baseName, long long frame, Amino::StringView targetExtension)
 Construct a file name with the specified frame number and extension. If the file name contains # or @ they will be replaced with the given frame number. # will reserve 4 digits for the frame number, whereas @ will reserve just one. If a target file extension is specified it will be enforced, otherwise will be ignored. More...
 
Amino::String Bifrost::FileUtils::extractFilename (Amino::StringView filePath)
 Get the filename (with extension) from a file path. The input is first processed by makePreferred. Then the extraction follows C++17 std::filesystem. More...
 
bool Bifrost::FileUtils::filePathExists (Amino::StringView filePath, Amino::String *out_errorMessage=nullptr)
 Verify if a file path exists. More...
 
Amino::String Bifrost::FileUtils::getRelativePath (Amino::StringView path, Amino::StringView baseDirectory)
 Return the valid relative path of the input path with respect to baseDirectory. More...
 
bool Bifrost::FileUtils::exists (Amino::StringView path, Amino::String *errorMessage=nullptr)
 Verify if a path exists. More...
 
bool Bifrost::FileUtils::tempDirectoryPath (Amino::String &tempDirectoryPath, Amino::String *errorMessage=nullptr)
 Returns the directory location suitable for temporary files. More...
 
bool Bifrost::FileUtils::removeAll (Amino::StringView path, Amino::String *errorMessage=nullptr)
 

Detailed Description

File utilities.

Function Documentation

◆ createDirectories()

bool Bifrost::FileUtils::createDirectories ( Amino::StringView  path,
Amino::String errorMessage = nullptr 
)

Creates the directories in path that do not exist.

Parameters
[in]pathThe path of directories to create
[out]errorMessageOn failure, errorMessage will be set to a human-readable error message
Returns
True on success, false otherwise.

◆ currentPath()

bool Bifrost::FileUtils::currentPath ( Amino::String currentPath,
Amino::String errorMessage = nullptr 
)

Returns the current path.

The current path as returned by many operating systems is a dangerous global variable. It may be changed unexpectedly by a third-party or system library functions, or by another thread.

Parameters
[out]currentPathWill be set to the current path
[out]errorMessageOn failure, errorMessage will be set to a human-readable error message
Returns
True on success, false otherwise.

◆ exists()

bool Bifrost::FileUtils::exists ( Amino::StringView  path,
Amino::String errorMessage = nullptr 
)

Verify if a path exists.

This will return true if the path exists no matter whether it is a directory, file, symlink etc.

Parameters
[in]pathThe path.
[out]errorMessageOn failure, errorMessage will be set to a human-readable error message
Returns
True if the path exists.

◆ extractFilename()

Amino::String Bifrost::FileUtils::extractFilename ( Amino::StringView  filePath)

Get the filename (with extension) from a file path. The input is first processed by makePreferred. Then the extraction follows C++17 std::filesystem.

std::cout << extractFilename("/foo/bar.txt"); // outputs "bar.txt"
std::cout << extractFilename("/foo/bar"); // outputs "bar"
std::cout << extractFilename("/foo/bar/"); // outputs ""
std::cout << extractFilename("/"); // outputs ""
std::cout << extractFilename("."); // outputs "."
std::cout << extractFilename(".."); // outputs ".."
Parameters
[in]filePathThe file path.
Returns
The filename. The file name can be empty, ".", or "..". If no directory separators are found then filePath is returned.

◆ extractParentPath()

Amino::String Bifrost::FileUtils::extractParentPath ( Amino::StringView  path)

Returns the parent path of path. The input is first processed by makePreferred. Then the extraction follows C++17 std::filesystem.

std::cout << extractParentPath("/foo/bar.txt"); // outputs "/foo"
std::cout << extractParentPath("/foo/bar"); // outputs "/foo"
std::cout << extractParentPath("/foo/bar/"); // outputs "/foo/bar"
std::cout << extractParentPath("/"); // outputs "/"
std::cout << extractParentPath("."); // outputs ""
std::cout << extractParentPath(".."); // outputs ""
Parameters
[in]pathThe input path.
Returns
The parent path.

◆ filename()

Amino::String Bifrost::FileUtils::filename ( Amino::StringView  baseName,
long long  frame,
Amino::StringView  targetExtension 
)

Construct a file name with the specified frame number and extension. If the file name contains # or @ they will be replaced with the given frame number. # will reserve 4 digits for the frame number, whereas @ will reserve just one. If a target file extension is specified it will be enforced, otherwise will be ignored.

Parameters
[in]baseNameThe file name.
[in]frameThe frame.
[in]targetExtensionThe desired extension of the file.
Returns
The baseName, including the specified frame number and file extension.

◆ filePath()

Amino::String Bifrost::FileUtils::filePath ( Amino::StringView  directory,
Amino::StringView  filename 
)

Create a file path from a directory and an filename in an operating system / independent way.

Parameters
[in]directorydirectory name
[in]filenamefile name
Returns
constructed file path

◆ filePathExists()

bool Bifrost::FileUtils::filePathExists ( Amino::StringView  filePath,
Amino::String out_errorMessage = nullptr 
)

Verify if a file path exists.

Parameters
[in]filePathThe file path.
[out]out_errorMessageOn failure, errorMessage will be set to a human-readable error message
Returns
True if the file path exists

◆ getRelativePath()

Amino::String Bifrost::FileUtils::getRelativePath ( Amino::StringView  path,
Amino::StringView  baseDirectory 
)

Return the valid relative path of the input path with respect to baseDirectory.

Note: If a file path (instead of directory) is passed in baseDirectory parameter the behavior is undefined

Parameters
[in]pathThe path that needs to be processed.
[in]baseDirectoryBase directory used to build the relative path (relative to).
Returns
Valid relative path with respect to baseDirectory.

◆ isAbsolute()

bool Bifrost::FileUtils::isAbsolute ( Amino::StringView  path)

Checks if a path is absolute.

Parameters
[in]pathThe path to check.
Returns
True if absolute, false otherwise.

◆ makePreferred()

Amino::String Bifrost::FileUtils::makePreferred ( Amino::StringView  path)

Convert directory separator characters in the given string to the operating system's preferred character. (For unix systems this is a forward slash, and for Windows, a backslash)

Parameters
[in]pathThe path to convert
Returns
The converted path

◆ removeAll()

bool Bifrost::FileUtils::removeAll ( Amino::StringView  path,
Amino::String errorMessage = nullptr 
)

Recursively deletes the contents on path.

Deletes the contents of path (if it is a directory) and the contents of all its subdirectories, recursively, then deletes path itself as if by repeatedly applying the POSIX remove. Symlinks are not followed (symlink is removed, not its target).

Parameters
[in]pathThe path.
[out]errorMessageOn failure, errorMessage will be set to a human-readable error message
Returns
True on success, false otherwise.

◆ tempDirectoryPath()

bool Bifrost::FileUtils::tempDirectoryPath ( Amino::String tempDirectoryPath,
Amino::String errorMessage = nullptr 
)

Returns the directory location suitable for temporary files.

Parameters
[out]tempDirectoryPathWill be set to temporary directory path.
[out]errorMessageOn failure, errorMessage will be set to a human-readable error message
Returns
True on success, false otherwise.