From: Jason Stewart (res0054p_at_[hidden])
Date: 2002-01-23 16:41:26
I have written this class as well. Actually it was two classes, one for
filenames and one for pathnames. This was done this was to prevent
ambiguity when assigning a string to the class.
The syntax of the class that I wrote is like this:
Pathname path = CurrentDirectory();
path += "tmpdir";
if (!path .Exists())
Pathname child = "../otherdir";
Pathname absolute = Pathname::MakeAbsolute(child); // uses current directory
Pathname absolute = Pathname::MakeAbsolute(child, path); // uses specified
absolute.Chop(); // removes the last directory
Pathname etc = fname.Path();
string dir = etc.Directory(); // just directory part, no drive
string drive = etc.Drive(); // just drive letter (or unc server/share)
string base = fname.Base(); // filename (no path or extension)
string ext = fname.Ext();
fname.Ext(".txt"); // change extension to .txt
fname.Path("c:\tmp"); // Change path
string pathstr = etc.Get(); // converts to a string
That's the basics. I have not compiled this on platforms other than windows
but I tried to handle other cases when I could. To avoid portability
problems internally all separators are forward slashes (by default, you can
change it). Win32 functions all handle forward slashes just as well as
backslashes. On unix systems the Drive functions don't do anything. There
is a compile time constant that defines whether comparisons are
case-sensitive or not.
I also wrote a directory iterator that returns these types but it seems to
have been obsoleted by dir_it.
If there is interest, I can talk to my boss and see if we can just donate
the code, its not that much but it has been tested fairly well.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk