Dv::Util::Directory Class Reference

A Directory represents a pathname that refers to a possibly non-existing directory. More...

#include <file.h>

Inheritance diagram for Dv::Util::Directory:
Inheritance graph
[legend]
Collaboration diagram for Dv::Util::Directory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Directory (const std::string &path) throw (FileError)
 Constructor, note that path may not exist.
 Directory (const File &file) throw (FileError)
 Equivalent to Directory(file.str());.
 ~Directory ()
 Destructor.
const std::vector< std::string > & files () const throw (FileError)
 Return files (only filenames, not absolute paths) in the directory.
std::string file (const std::string &filename) const
 Return str()+"/"+filename, i.e.
std::string tempfile (const std::string &prefix) const throw (FileError)
 Return str()+"/"+temp_filename, where temp_filename starts with prefix, i.e.
std::string tempdir (const std::string &prefix) const throw (FileError)
 Return str()+"/"+temp_dirname, where temp_dirname starts with prefix, i.e.
bool cd () const throw (FileError)
 Change working directory.
void walk (FileOperation *fileop=NULL, DirectoryOperation *dirop=NULL)
 Performs a walk through the filesystem starting from this directory.

Static Public Member Functions

static std::string pwd () throw (FileError)
 Return absolute pathname of current working directory.

Private Member Functions

void refresh () const throw (FileError)
 Updates private data members, exist_ and type_.
void init () const throw (FileError)

Private Attributes

std::vector< std::string > files_

Detailed Description

A Directory represents a pathname that refers to a possibly non-existing directory.

It is privately derived from File, relevant File members are available, in addition tot the files() member that retrieves the files in an existing directory.

The following File members are available also in Directory:

File::exists, File::mkdir, File::path, File::str, File::realpath, File::relpath, File::last_modified, File::last_accessed, File::touch, File::chown, File::chgrp, File::chmod, File::rm, File::mv, File::rmfr

Definition at line 409 of file file.h.


Constructor & Destructor Documentation

Dv::Util::Directory::Directory ( const std::string &  path  )  throw (FileError)

Constructor, note that path may not exist.

Dv::Util::Directory::Directory ( const File file  )  throw (FileError)

Equivalent to Directory(file.str());.

Dv::Util::Directory::~Directory (  ) 

Destructor.


Member Function Documentation

const std::vector<std::string>& Dv::Util::Directory::files (  )  const throw (FileError) [inline]

Return files (only filenames, not absolute paths) in the directory.

If the directory does not exist, the vector is empty. The directory entries ``.'' and ``..'' are not included in the output of Dv::Util::Directory::files().

Definition at line 424 of file file.h.

References files_, and refresh().

std::string Dv::Util::Directory::file ( const std::string &  filename  )  const

Return str()+"/"+filename, i.e.

a pathname for a filename in directory.

std::string Dv::Util::Directory::tempfile ( const std::string &  prefix  )  const throw (FileError)

Return str()+"/"+temp_filename, where temp_filename starts with prefix, i.e.

a pathname for a temporary file in the directory.

Parameters:
prefix of name of file to be created in this directory.
Returns:
the filename
Warning:
This function calls mkstemp() which will actually create the corresponding file.
std::string Dv::Util::Directory::tempdir ( const std::string &  prefix  )  const throw (FileError)

Return str()+"/"+temp_dirname, where temp_dirname starts with prefix, i.e.

a pathname for a temporary subdirectory in the directory.

Parameters:
prefix of name of file to be created in this directory.
Returns:
the directoryname
Warning:
This function calls mkdtemp() which will actually create the corresponding directory.
bool Dv::Util::Directory::cd (  )  const throw (FileError)

Change working directory.

static std::string Dv::Util::Directory::pwd (  )  throw (FileError) [static]

Return absolute pathname of current working directory.

void Dv::Util::Directory::walk ( FileOperation fileop = NULL,
DirectoryOperation dirop = NULL 
)

Performs a walk through the filesystem starting from this directory.

The operation executes for each file (special files included, except directories) it encounters the operation fileop(), while for each directory a call to dirop() is done. Files and/or directories with ``permission denied'' for the user running the program are skipped.

Parameters:
fileop NULL or pointer to an instance of a subclass of FileOperation.
dirop NULL or pointer to an instance of a subclass of DirectoryOperation.
Warning:
This method catches all thrown exceptions of type FileError, otherwise the operation could be interupted by files that e.g. get deleted during the walk. Thus, if you need to catch exception of type Dv::Util::FileError, you should catch them in your subclass of Dv::Util::FileOperation and/or Dv::Util::DirectoryOperation.
void Dv::Util::Directory::refresh (  )  const throw (FileError) [private, virtual]

Updates private data members, exist_ and type_.

Reimplemented from Dv::Util::File.

Referenced by files().

void Dv::Util::Directory::init (  )  const throw (FileError) [private]

Member Data Documentation

std::vector<std::string> Dv::Util::Directory::files_ [private]

Definition at line 506 of file file.h.

Referenced by files().


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

dvutil-1.0.10 [ 5 December, 2009]