FilePath
by
Joe Strout
FilePath is a class which facilitates manipulating file
paths and file names in a platform-independent way. A FilePath may be
built from strings, or converted to a string, in one of three formats:
- kCommon -- basically, the Unix path format
- kNative -- whatever format paths have on
this particular OS
- kDefault -- whatever FilePath::defaultFormat
specifies (one of kCommon or kNative)
Constructors
FilePath may be called with a default constructor (which sets the new
FilePath to the default directory), or with a String (or character array)
which describes a relative directory.
Path Traversal
The SetTo(s,f) method sets the path to a new directory s
relative to its current value. f is the format; this
parameter defaults to kDefault. SetToCWD() sets the
path back to its original value (the current working directory), and
SetToParent sets the path to the directory which
contains its current value.
As a shorthand for SetTo(s), you may use the plus
operators (+ or +=).
Conversion
To get the current path value as a String, call
ToString(f), where f is an optional
format specifier which defaults to kDefault. If kDefault is good for
you, you can also just typecast your FilePath to a String.
Information
The FilePrefix() method returns the path up to (but not
including) the filename; e.g., if mypath was "this/that/theother.txt",
then mypath.FilePrefix() would return "this/that". Conversely, the
FileName() function would return "theother.txt".
FileType() returns a PathType -- one of kNonexistant,
kFile, kDirectory, or kOtherType.
Rename
The Rename(s) function renames the file or directory
pointed to by the path to a new name given by s. The file is renamed in
place; this function should not be used to move a file to a different
directory. (We'll have a "move" function in the future...)
Here's the code...
Please let me know if you have any problems or suggestions.
http://www-ncmir.ucsd.edu/~jstrout/classlib/FilePath.html
Last Updated:
9/23/96
Joe Strout (
joe@strout.net )