PTLib
Version 2.14.3
|
Class to represent a directory in the operating system file system. More...
#include <pdirect.h>
Public Member Functions | |
Construction | |
PDirectory () | |
Create a directory object of the current working directory. More... | |
PDirectory (const char *cpathname) | |
Create a directory object of the specified directory. More... | |
PDirectory (const PString &pathname) | |
Create a directory object of the specified directory. More... | |
PDirectory & | operator= (const PString &pathname) |
Set the directory to the specified path. More... | |
PDirectory & | operator= (const char *cpathname) |
Set the directory to the specified path. More... | |
Directory listing functions | |
virtual bool | Open (PFileInfo::FileTypes scanMask=PFileInfo::DefaultSearch) |
Open the directory for scanning its list of files. More... | |
virtual bool | Restart (PFileInfo::FileTypes scanMask=PFileInfo::DefaultSearch) |
Restart file list scan from the beginning of directory. More... | |
virtual bool | Next () |
Move to the next file in the directory scan. More... | |
virtual void | Close () |
Close the directory during or after a file list scan. More... | |
virtual PFilePathString | GetEntryName () const |
Get the name (without the volume or directory path) of the current entry in the directory scan. More... | |
virtual bool | IsSubDir () const |
Determine if the directory entry currently being scanned is itself another directory entry. More... | |
virtual bool | GetInfo (PFileInfo &info) const |
Get file information on the current directory entry. More... | |
Protected Member Functions | |
void | Construct () |
void | Destruct () |
Protected Attributes | |
PFileInfo::FileTypes | m_scanMask |
Mask of file types that the directory scan will return. More... | |
DIR * | directory |
PFileInfo * | entryInfo |
struct dirent * | entryBuffer |
Access functions | |
PDirectory | GetParent () const |
Get the directory for the parent to the current directory. More... | |
PFilePathString | GetVolume () const |
Get the volume name that the directory is in. More... | |
bool | IsRoot () const |
Determine if the directory is the root directory of a volume. More... | |
PDirectory | GetRoot () const |
Get the root directory of a volume. More... | |
PStringArray | GetPath () const |
Get the directory path as an array of strings. More... | |
bool | 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. More... | |
static PINLINE bool | IsSeparator (char ch) |
Determine if the character ch is a directory path separator. More... | |
File system functions | |
bool | Exists () const |
Test for if the directory exists. More... | |
bool | Change () const |
Change the current working directory to the objects location. More... | |
bool | Create (int perm=PFileInfo::DefaultDirPerms, bool recurse=false) const |
Create a new directory with the specified permissions. More... | |
bool | Remove () |
Delete the directory. More... | |
static bool | Exists (const PString &path) |
Test for if the specified directory exists. More... | |
static bool | Change (const PString &path) |
Change the current working directory to that specified. More... | |
static bool | Create (const PString &p, int perm=PFileInfo::DefaultDirPerms, bool recurse=false) |
Create a new directory as specified with the specified permissions. More... | |
static bool | Remove (const PString &path) |
Delete the specified directory. More... | |
Additional Inherited Members | |
![]() | |
typedef const char * | Initialiser |
enum | ConversionType { Pascal, Basic, Literal, Signed, Unsigned, Decimal, Exponent, ScaleSI, Printf, NumConversionTypes } |
![]() | |
static const PString & | Empty () |
Return an empty string. More... | |
![]() | |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
static const char * | Class () |
Get the name of the class as a C string. More... | |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
![]() | |
![]() |
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
.
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.
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.
pathname | Directory path name for new object. |
bool PDirectory::Change | ( | ) | const |
Change the current working directory to the objects location.
|
static |
Change the current working directory to that specified.
path | Directory file path. |
|
virtual |
Close the directory during or after a file list scan.
Referenced by Destruct().
|
protected |
bool PDirectory::Create | ( | int | perm = PFileInfo::DefaultDirPerms , |
bool | recurse = false |
||
) | const |
Create a new directory with the specified permissions.
|
static |
Create a new directory as specified with the specified permissions.
p | Directory file path. |
|
inlineprotected |
References Close(), and PContainer::Destruct().
bool PDirectory::Exists | ( | ) | const |
Test for if the directory exists.
|
static |
Test for if the specified directory exists.
path | Directory file path. |
|
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.
|
virtual |
Get file information on the current directory entry.
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.
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.
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".
bool 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.
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 |
bool PDirectory::IsRoot | ( | ) | const |
Determine if the directory is the root directory of a volume.
|
static |
Determine if the character ch
is a directory path separator.
ch | Character to check as being a separator. |
|
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.
|
virtual |
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.
|
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.
scanMask | Mask of files to provide. |
PDirectory& PDirectory::operator= | ( | const PString & | pathname | ) |
Set the directory to the specified path.
pathname | Directory path name for new object. |
PDirectory& PDirectory::operator= | ( | const char * | cpathname | ) |
Set the directory to the specified path.
cpathname | Directory path name for new object. |
bool PDirectory::Remove | ( | ) |
Delete the directory.
|
static |
Delete the specified directory.
path | Directory file path. |
|
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.
scanMask | Mask of files to provide. |
|
protected |
|
protected |
|
protected |
|
protected |
Mask of file types that the directory scan will return.