Click here to Skip to main content
Licence 
First Posted 19 Aug 2005
Views 50,981
Bookmarked 19 times

SplitPath

By | 7 Sep 2005 | Article
Splitting a path into its components.

Sorry, it should have been SplitPath.jpg

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()

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Achim Klein

Web Developer

Germany Germany

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThis is not thread safe PinmemberCodeScrubber10:00 8 Jun '10  
Generalthanks Pinmemberskydave22:48 14 Nov '07  
GeneralHave a look at boost.filesystem PinmemberGhost-Rider1:17 8 Sep '05  
GeneralRe: Have a look at boost.filesystem PinmemberAchim Klein2:19 8 Sep '05  
GeneralJust use the PathXXX Win32 Functions Pinmemberahz6:41 29 Aug '05  
GeneralRe: Just use the PathXXX Win32 Functions PinmemberAchim Klein8:18 29 Aug '05  
GeneralRe: Just use the PathXXX Win32 Functions Pinmembermilkplus7:52 19 Nov '09  
NewsUpdate PinmemberAchim Klein8:06 27 Aug '05  
Generalidea for future versions Pinmembermgama5:05 19 Aug '05  
GeneralRe: idea for future versions PinmemberHerbert Illfelder4:44 22 Aug '05  
QuestionUNC? PinsitebuilderUwe Keim3:03 19 Aug '05  
GeneralMine does... PinmemberKochise3:22 19 Aug '05  
GeneralRe: Mine does... Pinmemberpeterchen23:17 19 Aug '05  
GeneralRe: Mine does... PinmemberKochise0:19 20 Aug '05  
GeneralInteresting PinmemberGeert van Horrik2:58 19 Aug '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 7 Sep 2005
Article Copyright 2005 by Achim Klein
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid