Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

Directory Class Reference

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

#include <cxxtools/directory.h>

List of all members.

Public Types

typedef DirectoryIterator const_iterator

Public Member Functions

 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 () 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.

Protected Member Functions

 Directory ()
 Default Constructor.


Detailed Description

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

Iterator Example:

    Directory d("/usr");
    Directory::iterator it = d.begin();
    while (it != d.end())
    {
        std::cout << "name : " << *it << std::endl;
        ++it;
    }

Constructor & Destructor Documentation

Directory ( const std::string &  path  )  [explicit]

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

Directory ( const FileInfo fi  )  [explicit]

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


Member Function Documentation

const std::string& path (  )  const

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

std::string dirName (  )  const

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.)

void remove (  ) 

This object will be invalid after calling this method.

void move ( const std::string &  to  ) 

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

static std::string rootdir (  )  [static]

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

static std::string tmpdir (  )  [static]

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.

Copyright © 2008 The Tntnet Development Team
Tntnet 1.6