pathUtils.h File Reference

Definitions of basic path utilities in tf. More...

+ Include dependency graph for pathUtils.h:

Go to the source code of this file.

Functions

TF_API std::string TfRealPath (std::string const &path, bool allowInaccessibleSuffix=false, std::string *error=0)
 Returns the canonical path of the specified filename, eliminating any symbolic links encountered in the path. More...
 
TF_API std::string TfNormPath (std::string const &path, bool stripDriveSpecifier=false)
 Normalizes the specified path, eliminating double slashes, etc. More...
 
TF_API std::string::size_type TfFindLongestAccessiblePrefix (std::string const &path, std::string *error=0)
 Return the index delimiting the longest accessible prefix of path. More...
 
TF_API std::string TfAbsPath (std::string const &path)
 Returns the canonical absolute path of the specified filename. More...
 
TF_API std::string TfGetExtension (std::string const &path)
 Returns the extension for a file path. More...
 
TF_API std::string TfReadLink (std::string const &path)
 Returns the value of a symbolic link. More...
 
TF_API bool TfIsRelativePath (std::string const &path)
 Return true if and only if a path is relative (not absolute). More...
 
TF_API std::vector< std::string > TfGlob (std::vector< std::string > const &paths, unsigned int flags=ARCH_GLOB_DEFAULT)
 Expands one or more shell glob patterns. More...
 
TF_API std::vector< std::string > TfGlob (std::string const &path, unsigned int flags=ARCH_GLOB_DEFAULT)
 Expands a shell glob pattern. More...
 

Detailed Description

Definitions of basic path utilities in tf.

These are utilities that operate on paths (represented by strings as something like: "/chars/Buzz/Torso".

Definition in file pathUtils.h.

Function Documentation

◆ TfAbsPath()

TF_API std::string TfAbsPath ( std::string const &  path)

Returns the canonical absolute path of the specified filename.

This makes the specified path absolute, by prepending the current working directory. If the path is already absolute, it is returned unmodified. This function differs from TfRealPath in that the path may point to a symlink, or not exist at all, and still result in an absolute path, rather than an empty string.

◆ TfFindLongestAccessiblePrefix()

TF_API std::string::size_type TfFindLongestAccessiblePrefix ( std::string const &  path,
std::string *  error = 0 
)

Return the index delimiting the longest accessible prefix of path.

The returned value is safe to use to split the string via it's generalized copy constructor. If the entire path is accessible, return the length of the input string. If none of the path is accessible, return 0. Otherwise the index points to the path separator that delimits the existing prefix from the non-existing suffix.

Examples: suppose the paths /, /usr, and /usr/anim exist, but no other paths exist.

TfFindLongestAccessiblePrefix('/usr/anim') -> 9 TfFindLongestAccessiblePrefix('/usr/anim/foo') -> 9 TfFindLongestAccessiblePrefix('/foo/bar') -> 0

If an error occurs, and the error string is not null, it is set to the reason for the error. If the error string is set, the returned index is the path separator before the element at which the error occurred.

◆ TfGetExtension()

TF_API std::string TfGetExtension ( std::string const &  path)

Returns the extension for a file path.

If path is a directory path, an empty path, or a dotfile path, return the empty string. Otherwise return path 's dot-separated extension as a string(dot not included).

Examples:

TfGetExtension('/foo/bar') -> '' TfGetExtension('/foo/bar/foo.baz') -> 'baz' TfGetExtension('/foo.bar/foo.baz') -> 'baz' TfGetExtension('/foo/bar/foo.101.baz') -> 'baz' TfGetExtension('/foo/bar/.foo.baz') -> 'baz' TfGetExtension('/foo/bar/.foo') -> ''

◆ TfGlob() [1/2]

TF_API std::vector<std::string> TfGlob ( std::vector< std::string > const &  paths,
unsigned int  flags = ARCH_GLOB_DEFAULT 
)

Expands one or more shell glob patterns.

This is a wrapper to glob(3), which manages the C structures necessary to glob a pattern, returning a std::vector of results. If no flags are specified, the GLOB_MARK and GLOB_NOCHECK flags are set by default. GLOB_MARK marks directories which match the glob pattern with a trailing slash. GLOB_NOCHECK returns any unexpanded patterns in the result.

◆ TfGlob() [2/2]

TF_API std::vector<std::string> TfGlob ( std::string const &  path,
unsigned int  flags = ARCH_GLOB_DEFAULT 
)

Expands a shell glob pattern.

This form of Glob calls TfGlob. For efficiency reasons, if expanding more than one pattern, use the vector form. As with the vector form of TfGlob, if flags is not set, the default glob flags are GLOB_MARK and GLOB_NOCHECK.

◆ TfIsRelativePath()

TF_API bool TfIsRelativePath ( std::string const &  path)

Return true if and only if a path is relative (not absolute).

◆ TfNormPath()

TF_API std::string TfNormPath ( std::string const &  path,
bool  stripDriveSpecifier = false 
)

Normalizes the specified path, eliminating double slashes, etc.

This canonicalizes paths, removing any double slashes, and eliminiating '.', and '..' components of the path. This emulates the behavior of os.path.normpath in Python.

On Windows, all backslashes are converted to forward slashes and drive specifiers (e.g., "C:") are lower-cased. If stripDriveSpecifier is true, these drive specifiers are removed from the path.

◆ TfReadLink()

TF_API std::string TfReadLink ( std::string const &  path)

Returns the value of a symbolic link.

Returns the empty string on error or if path is not a symbolic link.

◆ TfRealPath()

TF_API std::string TfRealPath ( std::string const &  path,
bool  allowInaccessibleSuffix = false,
std::string *  error = 0 
)

Returns the canonical path of the specified filename, eliminating any symbolic links encountered in the path.

This is a wrapper to realpath(3), which caters for situations where the real realpath() would return a NULL string, such as the case where the path is really just a program name. The memory allocated by realpath is managed internally.

If allowInaccessibleSuffix is true, then this function will only invoke realpath on the longest accessible prefix of path, and then append the inaccessible suffix.

If error is provided, it is set to the error reason should an error occur while computing the real path. If no error occurs, the string is cleared.