Instantiating Host-Specific Pathnames and Pathname Parsers

Use instances of IHostPathName, together with an appropriate pathname parser, to represent file, directory or volume pathnames in the pathname format of a particular operating system. The following example constructs an IHostPathName object from a UNIX pathname and then constructs an IDirectory object using that host-specific pathname:

IHostPathName unixPath("/usr/local/bin");
IDirectory localBin(unixPath, IUnixPathNameParser());

Instantiating a Portable Pathname from a Host-Specific Pathname

Although host-specific pathnames are easy to use, you sometimes need to store or manipulate a pathname in a portable manner. The class IPathName, derived from ICompoundName, provides this portable functionality. IPathName represents full or partial paths to file system entities and allows you to specify file system entities via their absolute or relative pathnames.

You can instantiate IPathName directly from a host-specific pathname by specifying an path name parser or by using the system's default parser:

// specify a parser
IPathName aPath("abc/xyz", IUnixPathNameParser());

// use the default parser
IPathName aPath("abc/xyz");

You can also construct an IPathName from a IDirectory instance and a partial path relative to that directory. The partial path can be specified either as an IHostPathName or as another IPathName:

// partial path is IHostPathName
IPathName aPath(aDirectory, "abc/xyz", IUnixPathNameParser());

// partial path is IPathName
IPathName aPathName("abc/xyz", IUnixPathNameParser());
IPathName aPath(aDirectory, aPathName);

Appending and Retrieving Pathname Components

To append all the components from one path onto the end of another, use the append function. After this code executes, xyz will contain the path one/two/three/four/five:

IPathName xyz("one/two/three", IUnixPathNameParser());
IPathName abc("four/five");
xyz.append(abc);

To append a single component to a pathname, use the appendComponent function. After this code executes, abc will contain the path one/two/three:

IPathName abc(IHostPathName("one/two"),
    IUnixPathNameParser());
abc.appendComponent(IText("three"));

To retrieve the individual components of a pathname, use the functions componentAt and lastComponent:

IPathName abc("one/two/three", IUnixPathNameParser());

// will return "two"
IText compTwo = abc.componentAt(2);

// will return "three"
IText lastComp = abc.lastComponent();

Note: Indices start at one, just as in the Collections classes.



Introduction to the File System
Overview of Pathnames and Pathname Parsers
Host-Specific Pathnames
Pathname Parsers
Portable Pathnames
File System Exceptions


Getting a Pathname from a File System Entity
Instantiating a File System Entity from a Host-Specific Pathname
Instantiating a File System Entity from a Portable Pathname