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[])
{
FileSystemUtilities::CPath objPath("/Some file/on the "
"file system/with a really/bogus path/and.extension");
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;
}
}
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