libcommonc++  0.7
FileName Class Reference

A class representing a filename. More...

#include <FileName.h++>

Public Member Functions

 FileName ()
 Construct a new, empty FileName. More...
 
 FileName (const String &path)
 Construct a new FileName for the given path. More...
 
 FileName (const String &dir, const String &filename)
 Construct a new FileName for the given directory and filename. More...
 
 FileName (const FileName &other)
 Copy constructor. More...
 
 FileName (const char *path)
 Construct a new FileName for the given path. More...
 
FileNameoperator= (const FileName &other)
 Assignment operator. More...
 
FileNameoperator= (const String &path)
 Assignment operator. More...
 
FileNameoperator= (const char *path)
 Assignment operator. More...
 
 ~FileName ()
 Destructor. More...
 
String toString () const
 Get a String representation of the FileName. More...
 
String getPathName () const
 Get the full path represented by this FileName, as a String. More...
 
void setPathName (const String &path)
 Set the path for this FileName. More...
 
String getVolume () const
 Get the volume for this FileName. More...
 
void setVolume (const String &volume)
 Set the volume for this FileName. More...
 
String getDirectory () const
 Get the directory for this FileName. More...
 
void setDirectory (const String &dir)
 Set the directory for this FileName. More...
 
FileNamepushDirectory (const String &dir)
 Push a directory. More...
 
FileNamepopDirectory ()
 Pop a directory. More...
 
String getBaseName () const
 Get the base name from the FileName. More...
 
void setBaseName (const String &name)
 Set the base name for the FileName. More...
 
String getExtension () const
 Get the extension for the FileName. More...
 
void setExtension (const String &ext)
 Set the extension for the FileName. More...
 
String getFileName () const
 Get the filename for the FileName. More...
 
void setFileName (const String &name)
 Set the filename for the FileName. More...
 
bool isAbsolute () const
 Determine wheter the FileName represents an absolute or relative path. More...
 
FileNamecanonicalize ()
 Canonicalize the FileName. More...
 

Detailed Description

A class representing a filename.

The filename is composed of the following components, each of which can be individually modified:

  • A volume. This corresponds to the drive letter on Windows systems. It is unused on non-Windows systems.
  • A directory path. This is the path minus the final path component (the filename), unless the path ends in a file separator character, in which case the path is used as the directory, and the filename is blank.
  • A filename (the base name plus the extension).
  • A file base name.
  • A file extension.

Example: The Windows path C:\Program Files\TestProg\TestProg.exe breaks down as follows:
Volume: C:
Directory: \Program Files\TestProg\
Filename: TestProg.exe
Base name: TestProg
Extension: exe

Author
Mark Lindner

Constructor & Destructor Documentation

◆ FileName() [1/5]

FileName ( )

Construct a new, empty FileName.

◆ FileName() [2/5]

FileName ( const String path)

Construct a new FileName for the given path.

◆ FileName() [3/5]

FileName ( const String dir,
const String filename 
)

Construct a new FileName for the given directory and filename.

◆ FileName() [4/5]

FileName ( const FileName other)

Copy constructor.

◆ FileName() [5/5]

FileName ( const char *  path)

Construct a new FileName for the given path.

◆ ~FileName()

~FileName ( )

Destructor.

Member Function Documentation

◆ canonicalize()

FileName & canonicalize ( )

Canonicalize the FileName.

All "." components are removed and all ".." components are resolved. If there are more ".." components than literal components, an empty path will result.

◆ getBaseName()

String getBaseName ( ) const
inline

Get the base name from the FileName.

◆ getDirectory()

String getDirectory ( ) const
inline

Get the directory for this FileName.

◆ getExtension()

String getExtension ( ) const
inline

Get the extension for the FileName.

◆ getFileName()

String getFileName ( ) const

Get the filename for the FileName.

◆ getPathName()

String getPathName ( ) const

Get the full path represented by this FileName, as a String.

◆ getVolume()

String getVolume ( ) const
inline

Get the volume for this FileName.

For non-Windows systems, this will be an empty string.

◆ isAbsolute()

bool isAbsolute ( ) const

Determine wheter the FileName represents an absolute or relative path.

Returns
true if an absolute path, false otherwise.

◆ operator=() [1/3]

FileName & operator= ( const FileName other)

Assignment operator.

◆ operator=() [2/3]

FileName & operator= ( const String path)

Assignment operator.

◆ operator=() [3/3]

FileName & operator= ( const char *  path)

Assignment operator.

◆ popDirectory()

FileName & popDirectory ( )

Pop a directory.

Removes the rightmost path component from the directory component of the FileName.

◆ pushDirectory()

FileName & pushDirectory ( const String dir)

Push a directory.

The directory is added to the end of the directory component of the FileName.

Parameters
dirThe directory to push. May include multiple path components.

◆ setBaseName()

void setBaseName ( const String name)

Set the base name for the FileName.

◆ setDirectory()

void setDirectory ( const String dir)

Set the directory for this FileName.

◆ setExtension()

void setExtension ( const String ext)

Set the extension for the FileName.

◆ setFileName()

void setFileName ( const String name)

Set the filename for the FileName.

Parameters
nameThe filename. If name contains no path separators, it simply becomes the new filename. If it begins with a path separator, the call does nothing. Otherwise, it is treated as a relative path: it is appended to the path, and then the entire path is reparsed, with the last component of name becoming the new filename.

◆ setPathName()

void setPathName ( const String path)

Set the path for this FileName.

◆ setVolume()

void setVolume ( const String volume)

Set the volume for this FileName.

On non-Windows systems, this call has no effect.

◆ toString()

String toString ( ) const
inline

Get a String representation of the FileName.

Equivalent to getPathName().


The documentation for this class was generated from the following files: