Click here to Skip to main content
Licence 
First Posted 2 May 2005
Views 18,557
Bookmarked 6 times

FileSystem path string wrapper class

By | 2 May 2005 | Article
A simple class to encapsulate a file system path for easy manipulation.

Introduction

Here's a little something more for the Code Project crowd. I've had this class sitting around for ages on my hard drive and I use it extensively on pretty much all the projects that I've ever worked on that has anything to do with accessing a file on the file system. It's a really simple class that encapsulates the typical operations that I use while trying to manipulate file path strings on both UNIX and Windows platforms. It's easy to use and easy to incorporate into any project, hope it proves useful to you too!

Using the code

Simply include the required .h (Path.h) and .cpp (Path.cpp) into your current project, #include the .h file (Path.h) and away you go! Here's a simple example to get you started...

#include "Path.h"
int main  (int argc, const char *  argv[])
{
    // construct path object wiht char  *
    FileSystemUtilities::CPath  objPath("/Some file/on the "
               "file system/with a  really/bogus path/and.extension");

    // do stuff
    std::cout <<  objPath.c_str() << std::endl;
    std::cout <<  objPath.GetBaseFileName().c_str() << std::endl;
    std::cout <<  objPath.GetBaseFileTitle().c_str() << std::endl;
    std::cout <<  objPath.GetBaseFileExtension().c_str() << std::endl;
    std::cout <<  objPath.Depth() << std::endl;

    for(int i =  0; i <= objPath.Depth();  i++)
    {
         std::cout << objPath.GetParentAtDepthN(i).c_str() <<  std::endl;
    }
}

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

Parko

Web Developer

Australia Australia

Member

Parko, aka Simon Parkinson-Bates, spends his days cutting code, his evenings chasing after his 5.5 year old daughter and cleaning up after his 3.5 year old son, and his nights cutting code.

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
Generalthanks Pinmemberpeterchen4:23 3 May '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
Web03 | 2.5.120515.1 | Last Updated 2 May 2005
Article Copyright 2005 by Parko
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid