HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_DirUtil.h File Reference
#include "UT_API.h"
#include "UT_FileStat.h"
#include <SYS/SYS_Deprecated.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
#include <stdlib.h>
+ Include dependency graph for UT_DirUtil.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  UT_AbsolutePrefixType { Default, AllowAbsolutePathSuffix, AlwaysAbsolute }
 

Functions

UT_API int UTunixFullPathSpecified (const char *name)
 
UT_API int UTfullPathSpecified (const char *name)
 
UT_API bool UTisAbsolutePath (const char *filename)
 
UT_API bool UTisRootPath (const char *filename)
 
UT_API int UTgetRootPrefixLength (const char *filename)
 
UT_API const UT_StringArrayUTgetAbsolutePathPrefixes ()
 
UT_API void UTaddAbsolutePathPrefix (const char *prefix, UT_AbsolutePrefixType type=Default)
 
UT_API void UTmakeAbsoluteFilePath (UT_String &path, const char *basepath=nullptr)
 
UT_API void UTmakeAbsoluteFilePath (UT_StringHolder &path, const char *basepath=nullptr)
 
UT_API void UTmakeRelativeFilePath (UT_String &path, const char *basepath=nullptr, bool allow_relative_path_from_root=true)
 
UT_API void UTmakeRelativeFilePath (UT_StringHolder &path, const char *basepath=nullptr, bool allow_relative_path_from_root=true)
 
UT_API void UTrealPath (UT_String &path)
 
UT_API void UTrealPath (UT_StringHolder &path)
 
UT_API void UTrealPath (UT_String &path, bool support_missing_files)
 Same as UTrealPath but with support for missing files. More...
 
UT_API void UTrealPath (UT_StringHolder &path, bool support_missing_files)
 
UT_API void UTnormalizeFilePath (UT_String &path)
 
UT_API void UTnormalizeFilePath (UT_StringHolder &path)
 
UT_API void UTstripFileUrlPrefix (UT_String &path)
 
UT_API void UTstripFileUrlPrefix (UT_StringHolder &path)
 
UT_API bool UTisHiddenFile (const char *basepath, const char *filename)
 
UT_API bool UTisValidRegularFile (const char *path)
 
UT_API bool UTisValidDirectory (const char *path)
 Returns true if the given path is a readable directory. More...
 
UT_API bool UTisDirectory (const char *path)
 Returns true if path is a directory, without permission checks. More...
 
UT_API bool UTisRegularFile (const char *path)
 Returns true if path is a regular file, without permission checks. More...
 
UT_API bool UTfileExists (const char *path)
 
UT_API char * getUnixCwd (char *buffer, int maxlen)
 Get the current working directory. More...
 
UT_API int statLastRead (dirent *dp, const char *path, UT_FileStat &file_stat)
 
UT_API int statLastRead (dirent *dp, const char *path, UT_FileStat::FileType &file_type, const bool check_executable)
 

Enumeration Type Documentation

Enumerator
Default 
AllowAbsolutePathSuffix 
AlwaysAbsolute 

Definition at line 32 of file UT_DirUtil.h.

Function Documentation

UT_API char* getUnixCwd ( char *  buffer,
int  maxlen 
)

Get the current working directory.

UT_API int statLastRead ( dirent *  dp,
const char *  path,
UT_FileStat file_stat 
)

Do the equivalent of a stat on the last file from readdir. This will perform a stat call on Linux.

UT_API int statLastRead ( dirent *  dp,
const char *  path,
UT_FileStat::FileType file_type,
const bool  check_executable 
)

Specialization that only returns the file type of the directory entry. This should be called instead of statLastRead if you only need the type of the entry.

Note: On Linux, if this is called and the entry is a symlink or the underlying filesystem doesn't support obtaining file types when accessing a directory, this will incur a stat call.

Note: On Linux, if check_executable is true, this will incur a stat call.

UT_API void UTaddAbsolutePathPrefix ( const char *  prefix,
UT_AbsolutePrefixType  type = Default 
)

The "allow_absolute_path_suffix" parameter can be set to true to indicate that this root prefix can be followed by an absolute path to a file on disk. This matters because on Windows, an absolute path can start with "C:", which doesn't look like an absolute path by the normal metric of looking for a leading slash.

Examples:
FS/FS_HomeHelper.C.
UT_API bool UTfileExists ( const char *  path)

Returns true if file path exists, without permission checks. This is optimized for known platforms.

UT_API int UTfullPathSpecified ( const char *  name)
UT_API const UT_StringArray& UTgetAbsolutePathPrefixes ( )

Functions to manage the set of prefixes which Houdini treats as being valid ways to start an absolute path.

UT_API int UTgetRootPrefixLength ( const char *  filename)

UTgetRootPrefixLength() returns the length of the root part of the file path.

The remainder of the file path after the root part length will have one of the following forms: '/path/to/file' => for absolute paths 'relative/path/to/file' => for relative paths '' => for root paths

Some examples of input file paths and output root lengths: '/path/to/file' => 0 'relative/path/to/file' => 0 'C:/path/to/file' => 2 (Windows only) 'C:relative/path/to/file' => 2 (Windows only) '//path/to/file' => 1 (Windows only) '//path/to/file' => 0 (Unix only) 'file:///path/to/file' => 5 'file:/path/to/file' => 5 'file:relative/path/to/file'=> 5

UT_API bool UTisAbsolutePath ( const char *  filename)
UT_API bool UTisDirectory ( const char *  path)

Returns true if path is a directory, without permission checks.

UT_API bool UTisHiddenFile ( const char *  basepath,
const char *  filename 
)

Checks if the file name starts with '.'. basepath (parent directory) is ignored in non Windows envirenment, whereas in Windows full path is needed to see if the file has the hidden attribute.

UT_API bool UTisRegularFile ( const char *  path)

Returns true if path is a regular file, without permission checks.

UT_API bool UTisRootPath ( const char *  filename)
UT_API bool UTisValidDirectory ( const char *  path)

Returns true if the given path is a readable directory.

UT_API bool UTisValidRegularFile ( const char *  path)

Returns true if the given path is a readable, regular file, ie. not a directory.

UT_API void UTmakeAbsoluteFilePath ( UT_String path,
const char *  basepath = nullptr 
)

Functions to convert absolute paths into relative paths and vice versa, given a path and a "base" path which is used as the root location for relative paths. When basepath is not given, getUnixCwd() will be used.

UT_API void UTmakeAbsoluteFilePath ( UT_StringHolder path,
const char *  basepath = nullptr 
)
UT_API void UTmakeRelativeFilePath ( UT_String path,
const char *  basepath = nullptr,
bool  allow_relative_path_from_root = true 
)
UT_API void UTmakeRelativeFilePath ( UT_StringHolder path,
const char *  basepath = nullptr,
bool  allow_relative_path_from_root = true 
)
UT_API void UTnormalizeFilePath ( UT_String path)

Normalizes a file path. This means ensuring all slashes are forward slashes, removing redundant slashes, and collapsing '..' and '.' components as much as possible (whether they occur at the start or in the middle of the path).

UT_API void UTnormalizeFilePath ( UT_StringHolder path)
UT_API void UTrealPath ( UT_String path)

Resolves symlinks, symbolic links on a path. Calls ::realpath() or fs::canonical() depdending of the platform.

UT_API void UTrealPath ( UT_StringHolder path)
UT_API void UTrealPath ( UT_String path,
bool  support_missing_files 
)

Same as UTrealPath but with support for missing files.

UT_API void UTrealPath ( UT_StringHolder path,
bool  support_missing_files 
)
UT_API void UTstripFileUrlPrefix ( UT_String path)

If the path starts with "file:", strip off however much prefix is required to get the to "path" path. Note that there may be 0, 1, 2, or 3 slashes after "file:", and behavior may need to change based on OS (e.g. on Windows file:///C:/foo -> C:/foo, otherwise file:///foo/bar -> /foo/bar.

UT_API void UTstripFileUrlPrefix ( UT_StringHolder path)
UT_API int UTunixFullPathSpecified ( const char *  name)