Rhino C++ API  8.13
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
ON_FileSystemPath Class Reference

#include <opennurbs_file_utilities.h>

Public Types

enum  PathId : unsigned int {
  PathId::Unset = 0, PathId::DesktopDirectory = 1, PathId::DocumentsDirectory = 2, PathId::DownloadsDirectory = 3,
  PathId::HomeDirectory = 4
}
 ON_FileSystemPath::PathId identifies a collection of commonly used directories. Use ON_FileSystemPath::PlatformPath() to get the name of the directory. More...
 

Static Public Member Functions

static const ON_wString CleanPath (bool bTrimLeft, bool bTrimRight, bool bAllowWindowsUNCHostNameOrDiskLetter, bool bDeleteWindowsUNCHostNameOrDiskLetter, bool bExpandUser, const wchar_t directory_separator, const wchar_t *dirty_path)
 
static const ON_wString CleanPath (bool bTrimLeft, bool bTrimRight, bool bAllowWindowsUNCHostNameOrDiskLetter, bool bDeleteWindowsUNCHostNameOrDiskLetter, const wchar_t directory_separator, const wchar_t *dirty_path)
 
static const ON_wString CleanPath (const wchar_t *dirty_path)
 
static const ON_wString CombinePaths (const wchar_t *left_side, bool bLeftSideContainsFileName, const wchar_t *right_side, bool bRightSideContainsFileName, bool bAppendTrailingDirectorySeparator)
 
static const ON_wString CurrentDirectory (bool bWithTrailingDirectorySeparator)
 
static const ON_wString DirectoryFromPath (const wchar_t *path)
 
static const ON_wString ExpandUser (const char *dirty_path)
 
static const ON_wString ExpandUser (const wchar_t *dirty_path)
 
static const ON_wString FileNameExtensionFromPath (const wchar_t *path)
 
static const ON_wString FileNameFromPath (const wchar_t *path, bool bIncludeExtension)
 
static bool FilePathHas3dmExtension (const char *file_path, bool bAllow3dmbakExtension)
 
static bool FilePathHas3dmExtension (const wchar_t *file_path, bool bAllow3dmbakExtension)
 
static const ON_wString FullPathFromRelativePath (const wchar_t *base_path, bool bBasePathIncludesFileName, const wchar_t *relative_path)
 
static bool IsDirectory (const char *path)
 
static bool IsDirectory (const wchar_t *path)
 
static bool IsDirectorySeparator (char c, bool bAllowAlternate)
 
static bool IsDirectorySeparator (wchar_t c, bool bAllowAlternate)
 
static bool IsFile (const char *path)
 
static bool IsFile (const wchar_t *path)
 
static bool IsRelativePath (const wchar_t *path)
 
static bool IsRelativePath (const wchar_t *path, const wchar_t directory_separator)
 
static bool IsValidFileName (const char *file_name, bool bAllPlatforms)
 
static bool IsValidFileName (const wchar_t *file_name, bool bAllPlatforms)
 
static bool PathExists (const char *path)
 
static bool PathExists (const wchar_t *path)
 
static const ON_wString PlatformPath (ON_FileSystemPath::PathId path_id)
 
static bool PlatformPathIgnoreCase ()
 
static const ON_wString RelativePath (const wchar_t *full_path, bool bFullPathIncludesFileName, const wchar_t *base_path, bool bBasePathIncludesFileName)
 
static const ON_wString RemoveFileName (const wchar_t *path, ON_wString *file_name)
 
static const ON_wString RemoveVolumeName (const wchar_t *path, ON_wString *volume_name)
 
static void SplitPath (const char *path, ON_String *volume, ON_String *dir, ON_String *file_name_stem, ON_String *file_name_ext)
 
static void SplitPath (const char *path, ON_wString *volume, ON_wString *dir, ON_wString *file_name_stem, ON_wString *file_name_ext)
 
static void SplitPath (const wchar_t *path, ON_wString *volume, ON_wString *dir, ON_wString *file_name_stem, ON_wString *file_name_ext)
 
static void SplitPath (const wchar_t *path, ON_wString *volume, ON_wString *dir, ON_wString *file_name_stem_and_extension)
 
static const ON_wString VolumeAndDirectoryFromPath (const wchar_t *path)
 
static const ON_wString VolumeFromPath (const wchar_t *path)
 

Static Public Attributes

static const wchar_t AlternateDirectorySeparator
 
static const char AlternateDirectorySeparatorAsChar
 
static const wchar_t DirectorySeparator
 
static const char DirectorySeparatorAsChar
 

Member Enumeration Documentation

◆ PathId

enum ON_FileSystemPath::PathId : unsigned int
strong

ON_FileSystemPath::PathId identifies a collection of commonly used directories. Use ON_FileSystemPath::PlatformPath() to get the name of the directory.

Enumerator
Unset 

summary> The current user's home directory. /summary> summary> The current user's desktop directory. /summary>

DesktopDirectory 

summary> The current user's documents directory. /summary>

DocumentsDirectory 

summary> The current user's downloads directory. /summary>

DownloadsDirectory 

summary> The current user's home directory. /summary>

HomeDirectory 

Member Function Documentation

◆ CleanPath() [1/3]

static const ON_wString ON_FileSystemPath::CleanPath ( bool  bTrimLeft,
bool  bTrimRight,
bool  bAllowWindowsUNCHostNameOrDiskLetter,
bool  bDeleteWindowsUNCHostNameOrDiskLetter,
bool  bExpandUser,
const wchar_t  directory_separator,
const wchar_t *  dirty_path 
)
static

Description: Condenses ///< to / Condenses /./ to / Condenses /sfsdf/../ to / Sets all directory separators to directory_separator. Parameters: bAllowWindowsUNCHostNameOrDiskLetter - [in] If bAllowWindowsUNCHostNameOrDiskLetter and the path begins with \HostName followed by a directory separator, then the initial \ is not condensed. If the path begins with X: followed by a directory separator, where "X" is a single letter in the range A to Z or a to z, then the path is considered valid. bDeleteWindowsUNCHostNameOrDiskLetter - [in] If bAllowWindowsUNCHostNameOrDiskLetter is true and the path begins with a UNC host name or disk letter followed by a directory separator, then host name or disk letter is deleted. This is useful when using paths from a Windows platform on a non-Windows platform. bExpandUser - [in] If the path begins with ~ and ON_FileSystemPath::PlatformPath( ON_FileSystemPath::PathId::UserHomeDirectory ) is not empty, then the ~ is replaced with absolute path of user's home directory. directory_separator - [in] If 0 == directory_separator, then the first directory separator is kept when condensing occurs. ON_wString::FileSystemPathSeparator is a good choice if you want to use the current runtime's separator. dirty_path - [in] path to clean. Return: Cleaned path.

◆ CleanPath() [2/3]

static const ON_wString ON_FileSystemPath::CleanPath ( bool  bTrimLeft,
bool  bTrimRight,
bool  bAllowWindowsUNCHostNameOrDiskLetter,
bool  bDeleteWindowsUNCHostNameOrDiskLetter,
const wchar_t  directory_separator,
const wchar_t *  dirty_path 
)
static

◆ CleanPath() [3/3]

static const ON_wString ON_FileSystemPath::CleanPath ( const wchar_t *  dirty_path)
static

Description: Condenses ///< to / Condenses /./ to / Condenses /sfsdf/../ to / Trims left and right white space. Sets all directory separators to ON_FileSystemPath::DirectorySeparator. If the Platform is not windows, the UNC host names and volume letters are deleted.

◆ CombinePaths()

static const ON_wString ON_FileSystemPath::CombinePaths ( const wchar_t *  left_side,
bool  bLeftSideContainsFileName,
const wchar_t *  right_side,
bool  bRightSideContainsFileName,
bool  bAppendTrailingDirectorySeparator 
)
static

Description: Combine paths into a single valid path name. Remove internal .. and . directory references. If necessary remove file names. Parameters: left_side - [in] bLeftSideContainsFileName - [in] true if left_side path ends in a file name and that file name is removed and discarded. right_side - [in] bRightSideContainsFileName - [in] true if right_side path ends in a file name. If bAppendTrailingDirectorySeparator is true, that file name is removed and discarded. If bAppendTrailingDirectorySeparator is false, the returned path ends in that file name. bAppendTrailingDirectorySeparator - [in] If true, any file names are removed and a directory separator is appended to the returned string. Returns: a path made left_side + right_side Remarks: This function manipulates string information. This function does not look at storage media to see if the paths currently exist.

◆ CurrentDirectory()

static const ON_wString ON_FileSystemPath::CurrentDirectory ( bool  bWithTrailingDirectorySeparator)
static

Parameters: bWithTrailingDirectorySeparator - [in] true - returned path will have a trailing directory separator. false - returned path will not have a trailing directory separator. Returns: The platform current working directory which should be the directory where ON::OpenFile("fname","r") would look for a file named "fname".

◆ DirectoryFromPath()

static const ON_wString ON_FileSystemPath::DirectoryFromPath ( const wchar_t *  path)
static

Parameters: path - [in] path to split Returns: The directory portion of the path.

◆ ExpandUser() [1/2]

static const ON_wString ON_FileSystemPath::ExpandUser ( const char *  dirty_path)
static

Description: If the path begins with ~ and ON_FileSystemPath::PlatformPath( ON_FileSystemPath::PathId::UserHomeDirectory ) is not empty, then the ~ is replaced with absolute path of user's home directory.

◆ ExpandUser() [2/2]

static const ON_wString ON_FileSystemPath::ExpandUser ( const wchar_t *  dirty_path)
static

◆ FileNameExtensionFromPath()

static const ON_wString ON_FileSystemPath::FileNameExtensionFromPath ( const wchar_t *  path)
static

Parameters: path - [in] path to split Returns: The file name extension portion of the path, including the leading period or "dot".

◆ FileNameFromPath()

static const ON_wString ON_FileSystemPath::FileNameFromPath ( const wchar_t *  path,
bool  bIncludeExtension 
)
static

Parameters: path - [in] path to split bIncludeExtension - [in] Returns: The file name portion of the path.

◆ FilePathHas3dmExtension() [1/2]

static bool ON_FileSystemPath::FilePathHas3dmExtension ( const char *  file_path,
bool  bAllow3dmbakExtension 
)
static

◆ FilePathHas3dmExtension() [2/2]

static bool ON_FileSystemPath::FilePathHas3dmExtension ( const wchar_t *  file_path,
bool  bAllow3dmbakExtension 
)
static

◆ FullPathFromRelativePath()

static const ON_wString ON_FileSystemPath::FullPathFromRelativePath ( const wchar_t *  base_path,
bool  bBasePathIncludesFileName,
const wchar_t *  relative_path 
)
static

◆ IsDirectory() [1/2]

static bool ON_FileSystemPath::IsDirectory ( const char *  path)
static

◆ IsDirectory() [2/2]

static bool ON_FileSystemPath::IsDirectory ( const wchar_t *  path)
static

◆ IsDirectorySeparator() [1/2]

static bool ON_FileSystemPath::IsDirectorySeparator ( char  c,
bool  bAllowAlternate 
)
static

◆ IsDirectorySeparator() [2/2]

static bool ON_FileSystemPath::IsDirectorySeparator ( wchar_t  c,
bool  bAllowAlternate 
)
static

◆ IsFile() [1/2]

static bool ON_FileSystemPath::IsFile ( const char *  path)
static

◆ IsFile() [2/2]

static bool ON_FileSystemPath::IsFile ( const wchar_t *  path)
static

◆ IsRelativePath() [1/2]

static bool ON_FileSystemPath::IsRelativePath ( const wchar_t *  path)
static

Parameters: path - [in] path to test Returns: True if path begins with ../ or ..\ or ./ or .\

◆ IsRelativePath() [2/2]

static bool ON_FileSystemPath::IsRelativePath ( const wchar_t *  path,
const wchar_t  directory_separator 
)
static

Parameters: path - [in] path to test directory_separator - [in] If 0 == directory_separator, then either ON_wString::FileSystemPathSeparator or ON_wString::AlternateFileSystemPathSeparator is permitted as a directory separator. ON_wString::FileSystemPathSeparator is a good choice if you want to use the current runtime's separator. Returns: True if path begins with ../ or ./

◆ IsValidFileName() [1/2]

static bool ON_FileSystemPath::IsValidFileName ( const char *  file_name,
bool  bAllPlatforms 
)
static

Description: Determine if the file_name string is a permitted file name. Valid file names must be non empty, cannot have two periods in a row, and cannot contain directory separators, tildes, and other platform specific values. Parameters: file_name - [in] string to test. bAllPlatforms - [in] If true, test name for all supported platforms. Returns: True if the string can be a file name.

◆ IsValidFileName() [2/2]

static bool ON_FileSystemPath::IsValidFileName ( const wchar_t *  file_name,
bool  bAllPlatforms 
)
static

Description: Determine if the file_name string is a permitted file name. Valid file names must be non empty, cannot have two periods in a row, and cannot contain directory separators, tildes, and other platform specific values. Parameters: file_name - [in] string to test. bAllPlatforms - [in] If true, test name for all supported platforms. Returns: True if the string can be a file name.

◆ PathExists() [1/2]

static bool ON_FileSystemPath::PathExists ( const char *  path)
static

◆ PathExists() [2/2]

static bool ON_FileSystemPath::PathExists ( const wchar_t *  path)
static

◆ PlatformPath()

static const ON_wString ON_FileSystemPath::PlatformPath ( ON_FileSystemPath::PathId  path_id)
static

Parameters: path_id - [in] Specifies path to get. Returns: Requested path. If the path does not exist in the current context, the empty string is returned.

◆ PlatformPathIgnoreCase()

static bool ON_FileSystemPath::PlatformPathIgnoreCase ( )
static

Returns: true if the platform file system ignores case. Remarks: Windows and default installations of OS X 10.10.3, and default installations of the UNIX terminal interface in OS X 10.10.3 and later ignore case. In the case of OX X, a user can override the default setting.

◆ RelativePath()

static const ON_wString ON_FileSystemPath::RelativePath ( const wchar_t *  full_path,
bool  bFullPathIncludesFileName,
const wchar_t *  base_path,
bool  bBasePathIncludesFileName 
)
static

Description: Get a the relative path from base_path to full_path. Parameters: full_path - [in] base_path - [in]

Example full_path = L"c:/a/b/c/d/somefile.txt"; base_path = L"C:/A/B/X/Y/Z/model.3dm"; ON_wString::GetRelativePath(full_path,base_path) returns L"../../../c/d/somefile.txt"

Example full_path = L"c:/a/b/somefile.txt"; base_path = L"C:/A/B/model.3dm"; ON_wString::GetRelativePath(full_path,base_path) returns L"./somefile.txt"

Remarks: Path separators on the input can be mixed. Path separators on the returned relative path are ON_wString::FileSystemPathSeparator

◆ RemoveFileName()

static const ON_wString ON_FileSystemPath::RemoveFileName ( const wchar_t *  path,
ON_wString file_name 
)
static

Description: Removes file name from path. Parameters: path - [in] file system path with a file name. file_name - [out] If file_name is not nullptr, the removed portion of path is returned here. Returns: path with any file name removed. Remarks: This function uses on_wsplitpath() to decide if the path ends with characters that could be a file name. It does not inspect the file system to see if the file exists.

◆ RemoveVolumeName()

static const ON_wString ON_FileSystemPath::RemoveVolumeName ( const wchar_t *  path,
ON_wString volume_name 
)
static

Description: Removes Windows volume name from path. Parameters: path - [in] file system path volume_name - [out] If volume_name is not nullptr, the removed portion of path is returned here. Returns: path with any volume name removed. Remarks: This function uses on_wsplitpath() to decide if the path begins with characters that could be a volume name. It does not inspect the file system to see if the volume exists.

◆ SplitPath() [1/4]

static void ON_FileSystemPath::SplitPath ( const char *  path,
ON_String volume,
ON_String dir,
ON_String file_name_stem,
ON_String file_name_ext 
)
static

Description: Find the locations in a path the specify the drive, directory, file name and file extension. Parameters: path - [in] path to split volume - [out] (pass null if you don't need the volume) If volume is not null and the path parameter begins with a Windows volume specification, *volume will either be the Windows volume letter followed by the trailing colon or a Windows UNC \<hostname>. Otherwise volume will be the empty string. dir - [out] (pass null if you don't need the directory) If dir is not null and the path parameter contains a directory specification, then the returned value of *dir will be the directory specification including the trailing slash. file_name_stem - [out] (pass null if you don't need the file name stem) If file_name_stem is not null and the path parameter contains a file name specification, then the returned value of *file_name_stem will be the file name stem. file_name_ext - [out] (pass null if you don't need the extension) If file_name_ext is not null and the path parameter contains a file name extension specification, then the returned value of file_name_ext will be the file name extension including the initial '.' character. Remarks: This function will treat a front slash ( / ) and a back slash ( \ ) as directory separators. Because this function parses file names store in .3dm files and the .3dm file may have been written on a Windows computer and then read on a another computer, it looks for a volume specification even when the operating system is not Windows. This function will not return an directory that does not end with a trailing slash. This function will not return an empty filename and a non-empty extension. This function parses the path string according to these rules. It does not check the actual file system to see if the answer is correct. See Also: on_splitpath

◆ SplitPath() [2/4]

static void ON_FileSystemPath::SplitPath ( const char *  path,
ON_wString volume,
ON_wString dir,
ON_wString file_name_stem,
ON_wString file_name_ext 
)
static

◆ SplitPath() [3/4]

static void ON_FileSystemPath::SplitPath ( const wchar_t *  path,
ON_wString volume,
ON_wString dir,
ON_wString file_name_stem,
ON_wString file_name_ext 
)
static

◆ SplitPath() [4/4]

static void ON_FileSystemPath::SplitPath ( const wchar_t *  path,
ON_wString volume,
ON_wString dir,
ON_wString file_name_stem_and_extension 
)
static

◆ VolumeAndDirectoryFromPath()

static const ON_wString ON_FileSystemPath::VolumeAndDirectoryFromPath ( const wchar_t *  path)
static

Parameters: path - [in] path to split Returns: The volume and directory portion of the path.

◆ VolumeFromPath()

static const ON_wString ON_FileSystemPath::VolumeFromPath ( const wchar_t *  path)
static

Parameters: path - [in] path to split Returns: The volume portion of the path.

Member Data Documentation

◆ AlternateDirectorySeparator

const wchar_t ON_FileSystemPath::AlternateDirectorySeparator
static

◆ AlternateDirectorySeparatorAsChar

const char ON_FileSystemPath::AlternateDirectorySeparatorAsChar
static

◆ DirectorySeparator

const wchar_t ON_FileSystemPath::DirectorySeparator
static

◆ DirectorySeparatorAsChar

const char ON_FileSystemPath::DirectorySeparatorAsChar
static

Platform dependent character used to separate directory names. On Windows platforms: ON_FileSystemPath::DirectorySeparator = ON_wString::Backslash. On UNIX (including modern Apple) platforms: ON_FileSystemPath::DirectorySeparator = ON_wString::Slash.