PDirectory Class Reference

Class to represent a directory in the operating system file system. More...

#include <pdirect.h>

Inheritance diagram for PDirectory:

PFilePathString PString PCharArray PBaseArray< T > PAbstractArray PContainer PObject List of all members.

Access functions

PDirectory GetParent () const
 Get the directory for the parent to the current directory.
PFilePathString GetVolume () const
 Get the volume name that the directory is in.
PBoolean IsRoot () const
 Determine if the directory is the root directory of a volume.
PDirectory GetRoot () const
 Get the root directory of a volume.
PStringArray GetPath () const
 Get the directory path as an array of strings.
PBoolean GetVolumeSpace (PInt64 &total, PInt64 &free, DWORD &clusterSize) const
 Determine the total number of bytes and number of bytes free on the volume that this directory is contained on.
static PINLINE PBoolean IsSeparator (char ch)
 Determine if the character ch is a directory path separator.

File system functions

PBoolean Exists () const
 Test for if the directory exists.
PBoolean Change () const
 Change the current working directory to the objects location.
PBoolean Create (int perm=PFileInfo::DefaultDirPerms) const
 Create a new directory with the specified permissions.
PBoolean Remove ()
 Delete the directory.
static PBoolean Exists (const PString &path)
 Test for if the specified directory exists.
static PBoolean Change (const PString &path)
 Change the current working directory to that specified.
static PBoolean Create (const PString &p, int perm=PFileInfo::DefaultDirPerms)
 Create a new directory as specified with the specified permissions.
static PBoolean Remove (const PString &path)
 Delete the specified directory.

Public Member Functions

Construction
 PDirectory ()
 Create a directory object of the current working directory.
 PDirectory (const char *cpathname)
 Create a directory object of the specified directory.
 PDirectory (const PString &pathname)
 Create a directory object of the specified directory.
PDirectoryoperator= (const PString &pathname)
 Set the directory to the specified path.
PDirectoryoperator= (const char *cpathname)
 Set the directory to the specified path.
Directory listing functions
virtual PBoolean Open (int scanMask=PFileInfo::AllFiles)
 Open the directory for scanning its list of files.
virtual PBoolean Restart (int scanMask=PFileInfo::AllFiles)
 Restart file list scan from the beginning of directory.
PBoolean Next ()
 Move to the next file in the directory scan.
virtual void Close ()
 Close the directory during or after a file list scan.
virtual PFilePathString GetEntryName () const
 Get the name (without the volume or directory path) of the current entry in the directory scan.
virtual PBoolean IsSubDir () const
 Determine if the directory entry currently being scanned is itself another directory entry.
virtual PBoolean GetInfo (PFileInfo &info) const
 Get file information on the current directory entry.

Protected Member Functions

void Construct ()
void Destruct ()
 Internal function called from container destructors.

Protected Attributes

int scanMask
 Mask of file types that the directory scan will return.
DIR * directory
PFileInfoentryInfo
dirent * entryBuffer

Detailed Description

Class to represent a directory in the operating system file system.

A directory is a special file that contains a list of file paths.

The directory paths are highly platform dependent and a minimum number of assumptions should be made.

The PDirectory object is a string consisting of a possible volume name, and a series directory names in the path from the volumes root to the directory that the object represents. Each directory is separated by the platform dependent separator character which is defined by the PDIR_SEPARATOR macro. The path always has a trailing separator.

Some platforms allow more than one character to act as a directory separator so when doing any processing the IsSeparator() function should be used to determine if a character is a possible separator.

The directory may be opened to gain access to the list of files that it contains. Note that the directory does {not} contain the "." and ".." entries that some platforms support.

The ancestor class is dependent on the platform. For file systems that are case sensitive, eg Unix, the ancestor is PString. For other platforms, the ancestor class is PCaselessString.


Constructor & Destructor Documentation

PDirectory::PDirectory (  ) 

Create a directory object of the current working directory.

PDirectory::PDirectory ( const char *  cpathname  ) 

Create a directory object of the specified directory.

The cpathname parameter may be a relative directory which is made absolute by the creation of the PDirectory object.

Parameters:
cpathname  Directory path name for new object.

PDirectory::PDirectory ( const PString pathname  ) 

Create a directory object of the specified directory.

The pathname parameter may be a relative directory which is made absolute by the creation of the PDirectory object.

Parameters:
pathname  Directory path name for new object.


Member Function Documentation

static PBoolean PDirectory::Change ( const PString path  )  [static]

Change the current working directory to that specified.

Returns:
true if current working directory was changed.
Parameters:
path  Directory file path.

PBoolean PDirectory::Change (  )  const

Change the current working directory to the objects location.

Returns:
true if current working directory was changed.

virtual void PDirectory::Close (  )  [virtual]

Close the directory during or after a file list scan.

void PDirectory::Construct (  )  [protected]

static PBoolean PDirectory::Create ( const PString p,
int  perm = PFileInfo::DefaultDirPerms 
) [static]

Create a new directory as specified with the specified permissions.

Returns:
true if directory created.
Parameters:
p  Directory file path.
perm  Permission on new directory.

PBoolean PDirectory::Create ( int  perm = PFileInfo::DefaultDirPerms  )  const

Create a new directory with the specified permissions.

Returns:
true if directory created.

void PDirectory::Destruct (  )  [inline, protected]

Internal function called from container destructors.

This will conditionally call DestroyContents() to destroy the container contents.

Reimplemented from PContainer.

static PBoolean PDirectory::Exists ( const PString path  )  [static]

Test for if the specified directory exists.

Returns:
true if directory exists.
Parameters:
path  Directory file path.

PBoolean PDirectory::Exists (  )  const

Test for if the directory exists.

Returns:
true if directory exists.

virtual PFilePathString PDirectory::GetEntryName (  )  const [virtual]

Get the name (without the volume or directory path) of the current entry in the directory scan.

This may be the name of a file or a subdirectory or even a link or device for operating systems that support them.

To get a full path name concatenate the PDirectory object itself with the entry name.

Note that the directory scan will {not} return the "." and ".." entries that some platforms support.

Returns:
string for directory entry.

virtual PBoolean PDirectory::GetInfo ( PFileInfo info  )  const [virtual]

Get file information on the current directory entry.

Returns:
true if file information was successfully retrieved.
Parameters:
info  Object to receive the file information.

PDirectory PDirectory::GetParent (  )  const

Get the directory for the parent to the current directory.

If the directory is already the root directory it returns the root directory again.

Returns:
parent directory.

PStringArray PDirectory::GetPath (  )  const

Get the directory path as an array of strings.

The first element in the array is the volume string, eg under Win32 it is "c:" or "\\machine", while under unix it is an empty string.

PDirectory PDirectory::GetRoot (  )  const

Get the root directory of a volume.

Returns:
root directory.

PFilePathString PDirectory::GetVolume (  )  const

Get the volume name that the directory is in.

This is platform dependent, for example for MS-DOS it is the 11 character volume name for the drive, eg "DOS_DISK", and for Macintosh it is the disks volume name eg "Untitled". For a unix platform it is the device name for the file system eg "/dev/sda1".

Returns:
string for the directory volume.

PBoolean PDirectory::GetVolumeSpace ( PInt64 &  total,
PInt64 &  free,
DWORD &  clusterSize 
) const

Determine the total number of bytes and number of bytes free on the volume that this directory is contained on.

Note that the free space will be the physical limit and if user quotas are in force by the operating system, the use may not actually be able to use all of these bytes.

Returns:
true if the information could be determined.
Parameters:
total  Total number of bytes available on volume
free  Number of bytes unused on the volume
clusterSize  "Quantisation factor" in bytes for files on volume

PBoolean PDirectory::IsRoot (  )  const

Determine if the directory is the root directory of a volume.

Returns:
true if the object is a root directory.

static PINLINE PBoolean PDirectory::IsSeparator ( char  ch  )  [static]

Determine if the character ch is a directory path separator.

Returns:
true if may be used to separate directories in a path.
Parameters:
ch  Character to check as being a separator.

virtual PBoolean PDirectory::IsSubDir (  )  const [virtual]

Determine if the directory entry currently being scanned is itself another directory entry.

Note that the directory scan will {not} return the "." and ".." entries that some platforms support.

Returns:
true if entry is a subdirectory.

PBoolean PDirectory::Next (  ) 

Move to the next file in the directory scan.

Only files that are of a type that is specified in the mask passed to the Open() or Restart() functions will be returned.

Note that the directory scan will {not} return the "." and ".." entries that some platforms support.

Returns:
true if there is another valid file in the directory.

virtual PBoolean PDirectory::Open ( int  scanMask = PFileInfo::AllFiles  )  [virtual]

Open the directory for scanning its list of files.

Once opened the GetEntryName() function may be used to get the current directory entry and the Next() function used to move to the next directory entry.

Only files that are of a type that is specified in the mask will be returned.

Note that the directory scan will {not} return the "." and ".." entries that some platforms support.

Returns:
true if directory was successfully opened, and there was at least one file in it of the specified types.
Parameters:
scanMask  Mask of files to provide.

PDirectory& PDirectory::operator= ( const char *  cpathname  ) 

Set the directory to the specified path.

Parameters:
cpathname  Directory path name for new object.

Reimplemented from PString.

PDirectory& PDirectory::operator= ( const PString pathname  ) 

Set the directory to the specified path.

Parameters:
pathname  Directory path name for new object.

Reimplemented from PString.

static PBoolean PDirectory::Remove ( const PString path  )  [static]

Delete the specified directory.

Returns:
true if directory was deleted.
Parameters:
path  Directory file path.

PBoolean PDirectory::Remove (  ) 

Delete the directory.

Returns:
true if directory was deleted.

virtual PBoolean PDirectory::Restart ( int  scanMask = PFileInfo::AllFiles  )  [virtual]

Restart file list scan from the beginning of directory.

This is similar to the Open() command but does not require that the directory be closed (using Close()) first.

Only files that are of a type that is specified in the mask will be returned.

Note that the directory scan will {not} return the "." and ".." entries that some platforms support.

Returns:
true if directory was successfully opened, and there was at least one file in it of the specified types.
Parameters:
scanMask  Mask of files to provide.


Member Data Documentation

DIR* PDirectory::directory [protected]

struct dirent* PDirectory::entryBuffer [protected]

PFileInfo* PDirectory::entryInfo [protected]

int PDirectory::scanMask [protected]

Mask of file types that the directory scan will return.


The documentation for this class was generated from the following file:
Generated on Fri Oct 14 01:44:11 2011 for PTLib by  doxygen 1.4.7