Represents a single directory in the file-system. More...

#include <cxxtools/directory.h>

Public Types

typedef DirectoryIterator const_iterator

Public Member Functions

 Directory ()
 Default Constructor.
 Directory (const std::string &path)
 Constructs a Directory object from the path path.
 Directory (const FileInfo &fi)
 Constructs a Directory object from a FileInfo object.
 Directory (const Directory &dir)
 Copy constructor.
 ~Directory ()
 Destructor.
Directoryoperator= (const Directory &dir)
 Assignment operator.
const std::string & path () const
 Returns the path of the directory.
std::size_t size () const
 Returns the size of the directory in bytes.
std::string dirName () const
 Returns the parent directory path.
std::string name () const
 Returns the name of the directory excluding the path.
void remove ()
 Removes the directory.
void move (const std::string &to)
 Moves the directory to the location given by to.
const_iterator begin (bool skipHiden=false) const
 Returns an iterator to the first entry in the directory.
const_iterator end () const
 Returns an iterator to the end of the directory entries.

Static Public Member Functions

static Directory create (const std::string &path)
 Creates a new directory at the path given by path.
static bool exists (const std::string &path)
 Returns true if a directory exists at path, or false otherwise.
static void chdir (const std::string &path)
 Changes the current directory.
static std::string cwd ()
 Returns the current directory.
static std::string curdir ()
 Returns the string representng the current directory in path names.
static std::string updir ()
 Returns the string representng the upper directory in path names.
static std::string rootdir ()
 Returns the system root path.
static std::string tmpdir ()
 Returns the systems tmp directory.
static std::string sep ()
 Returns the string representng the separator in path names.

Detailed Description

Represents a single directory in the file-system.

This class contains methods to create, move, delete directories and gives to possibility to iterate over the contents of the directory.

Iterator Example:

for (cxxtools::DirectoryIterator it = d.begin(); it != d.end(); ++it)
{
std::cout << "name: " << *it << std::endl;
}

Member Typedef Documentation

Constructor & Destructor Documentation

cxxtools::Directory::Directory ( )

Default Constructor.

cxxtools::Directory::Directory ( const std::string &  path)
explicit

Constructs a Directory object from the path path.

If no directory exists at path, an exception of type DirectoryNotFound is thrown.

cxxtools::Directory::Directory ( const FileInfo fi)
explicit

Constructs a Directory object from a FileInfo object.

An exception of type DirectoryNotFound is thrown if the FileInfo does not represent a directory.

cxxtools::Directory::Directory ( const Directory dir)

Copy constructor.

cxxtools::Directory::~Directory ( )

Destructor.

Member Function Documentation

const_iterator cxxtools::Directory::begin ( bool  skipHiden = false) const

Returns an iterator to the first entry in the directory.

static void cxxtools::Directory::chdir ( const std::string &  path)
static

Changes the current directory.

static Directory cxxtools::Directory::create ( const std::string &  path)
static

Creates a new directory at the path given by path.

static std::string cxxtools::Directory::curdir ( )
static

Returns the string representng the current directory in path names.

static std::string cxxtools::Directory::cwd ( )
static

Returns the current directory.

std::string cxxtools::Directory::dirName ( ) const

Returns the parent directory path.

This method might return an empty string if the node was created without a complete path. If the directory is located in the root directory of a unix file system, a slash ("/") is returned. A returned directory path always ends with a trailing path separator character. (A backslash in Windows and a slash in Unix, for example.)

const_iterator cxxtools::Directory::end ( ) const

Returns an iterator to the end of the directory entries.

static bool cxxtools::Directory::exists ( const std::string &  path)
static

Returns true if a directory exists at path, or false otherwise.

void cxxtools::Directory::move ( const std::string &  to)

Moves the directory to the location given by to.

The Directory object will stay valid after this method was called and point to the moved directory.

std::string cxxtools::Directory::name ( ) const

Returns the name of the directory excluding the path.

Directory& cxxtools::Directory::operator= ( const Directory dir)

Assignment operator.

const std::string& cxxtools::Directory::path ( ) const
inline

Returns the path of the directory.

This method may return a relative path, or a fully qualified one depending on how this object was constructed.

void cxxtools::Directory::remove ( )

Removes the directory.

This object will be invalid after calling this method.

static std::string cxxtools::Directory::rootdir ( )
static

Returns the system root path.

Returns "/" (root) on Linux, "c:\" on Windows

static std::string cxxtools::Directory::sep ( )
static

Returns the string representng the separator in path names.

std::size_t cxxtools::Directory::size ( ) const

Returns the size of the directory in bytes.

static std::string cxxtools::Directory::tmpdir ( )
static

Returns the systems tmp directory.

The environment variables TEMP and TMP are checked first. If not set, "/tmp" is returned if it exists. If none of the environment variables are set and the default system tmp directory does not exist, the current directory is returned.

static std::string cxxtools::Directory::updir ( )
static

Returns the string representng the upper directory in path names.


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