#include <opennurbs_file_utilities.h>

Public Types

enum  PathId : unsigned int { PathId::Unset = 0, PathId::DesktopDirectory = 1, PathId::DocumentsDirectory = 2, PathId::DownloadsDirectory = 3 }
 ids used by ON_FileSystemPath::GetPath() More...
 

Static Public Member Functions

static const ON_wString CleanPath (bool bTrimLeft, bool bTrimRight, bool bAllowWindowsUNCHostNameOrDiskLetter, bool bDeleteWindowsUNCHostNameOrDiskLetter, const wchar_t directory_separator, const wchar_t *dirty_path)
 Condenses // to / Condenses /./ to / Condenses /sfsdf/../ to / Sets all directory separators to directory_separator. More...
 
static const ON_wString CleanPath (const wchar_t *dirty_path)
 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. More...
 
static const ON_wString CombinePaths (const wchar_t *left_side, bool bLeftSideContainsFileName, const wchar_t *right_side, bool bRightSideContainsFileName, bool bAppendTrailingDirectorySeparator)
 Combine paths into a single valid path name. Remove internal .. and . directory references. If necessary remove file names. More...
 
static const ON_wString CurrentDirectory (bool bWithTrailingDirectorySeparator)
 
static const ON_wString DirectoryFromPath (const wchar_t *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 wchar_t *file_path, bool bAllow3dmbakExtension)
 
static bool FilePathHas3dmExtension (const char *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, const wchar_t directory_separator)
 
static bool IsRelativePath (const wchar_t *path)
 
static bool IsValidFileName (const char *file_name, bool bAllPlatforms)
 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. More...
 
static bool IsValidFileName (const wchar_t *file_name, bool bAllPlatforms)
 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. More...
 
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)
 Get a the relative path from base_path to full_path. More...
 
static const ON_wString RemoveFileName (const wchar_t *path, ON_wString *file_name)
 Removes file name from path. More...
 
static const ON_wString RemoveVolumeName (const wchar_t *path, ON_wString *volume_name)
 Removes Windows volume name from path. More...
 
static void SplitPath (const char *path, ON_String *volume, ON_String *dir, ON_String *file_name_stem, ON_String *file_name_ext)
 Find the locations in a path the specify the drive, directory, file name and file extension. More...
 
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

ids used by ON_FileSystemPath::GetPath()

Enumerator
Unset 
DesktopDirectory 
DocumentsDirectory 
DownloadsDirectory 

Member Function Documentation

◆ CleanPath() [1/2]

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

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
nonWindows platform.
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/2]

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

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

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

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]
truereturned path will have a trailing directory separator.
falsereturned 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.

◆ 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, inlcuding 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 wchar_t *  file_path,
bool  bAllow3dmbakExtension 
)
static

◆ FilePathHas3dmExtension() [2/2]

static bool ON_FileSystemPath::FilePathHas3dmExtension ( const char *  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,
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 ./

◆ IsRelativePath() [2/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 .\

◆ IsValidFileName() [1/2]

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

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

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.

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

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"

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

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.

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

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.

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

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.

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