SplitPath






2.84/5 (16 votes)
Aug 19, 2005

83364

1161
Splitting a path into its components.
Introduction
Most applications have to handle path names somewhere along the way. This simple class (actually it's more a collection of static methods) provides nine functions that make the different parts of a path accessible. Groundbreaking ideas are not included, but creating relative path names in any direction across a drive might be a useful feature.
Using the code
The most often problems should have the most easiest solutions. So here it comes:
// get drive letter
CString drive = PathInfo::getDrive(Path);
// get directory
CString dir = PathInfo::getDirectory(Path);
// get folder
CString folder = PathInfo::getFolder(Path);
// get name (title + extension)
CString name = PathInfo::getName(Path);
// get title
CString title = PathInfo::getTitle(Path);
// get extension
CString extsn = PathInfo::getExtension(Path);
// change extension ("cfg" for example) CString cfgPath = PathInfo::getPathAs(Path, "cfg");
// switch absolute to relative path
CString relPath = PathInfo::getRelPath(Path, Origin);
// switch relative to absolute path
CString absPath = PathInfo::getAbsPath(relPath, Origin);
History
Version 1.1
Changed:
- The GUI now allows textual input for testing purpose.
getRelPath()
now uses_strnicmp()
to compare strings.
Version 1.0
Added:
getDrive()
getDirectory()
getFolder()
getName()
getTitle()
getExtension()
getPathAs()
getRelPath()
getAbsPath()