pdirect.h
Go to the documentation of this file.
/*
* pdirect.h
*
* File system directory class.
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_DIRECTORY_H
#define PTLIB_DIRECTORY_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#ifdef Fifo
#undef Fifo
#endif
#ifdef _WIN32
#define PDIR_SEPARATOR '\\'
const PINDEX P_MAX_PATH = _MAX_PATH;
typedef PCaselessString PFilePathString;
#else
#define PDIR_SEPARATOR '/'
#define P_MAX_PATH (_POSIX_PATH_MAX)
typedef PString PFilePathString;
#endif
// File System
class PFileInfo : public PObject
{
PCLASSINFO(PFileInfo, PObject);
public:
enum FileTypes {
RegularFile = 1,
SymbolicLink = 2,
SubDirectory = 4,
CharDevice = 8,
BlockDevice = 16,
Fifo = 32,
SocketDevice = 64,
UnknownFileType = 256,
AllFiles = 0x1ff
};
FileTypes type;
PTime created;
PTime modified;
PTime accessed;
PUInt64 size;
enum Permissions {
WorldExecute = 1,
WorldWrite = 2,
WorldRead = 4,
GroupExecute = 8,
GroupWrite = 16,
GroupRead = 32,
UserExecute = 64,
UserWrite = 128,
UserRead = 256,
AllPermissions = 0x1ff,
DefaultPerms = UserRead|UserWrite|GroupRead|WorldRead,
DefaultDirPerms = DefaultPerms|UserExecute|GroupExecute|WorldExecute
};
int permissions;
PBoolean hidden;
};
class PDirectory : public PFilePathString
{
PCONTAINERINFO(PDirectory, PFilePathString);
public:
PDirectory();
PDirectory(
const char * cpathname
);
PDirectory(
const PString & pathname
);
PDirectory & operator=(
const PString & pathname
);
PDirectory & operator=(
const char * cpathname
);
PDirectory GetParent() const;
PFilePathString GetVolume() const;
PBoolean IsRoot() const;
PDirectory GetRoot() const;
PStringArray GetPath() const;
PINLINE static PBoolean IsSeparator(
char ch
);
PBoolean GetVolumeSpace(
PInt64 & total,
PInt64 & free,
DWORD & clusterSize
) const;
PBoolean Exists() const;
static PBoolean Exists(
const PString & path
);
PBoolean Change() const;
static PBoolean Change(
const PString & path
);
PBoolean Create(
int perm = PFileInfo::DefaultDirPerms // Permission on new directory.
) const;
static PBoolean Create(
const PString & p,
int perm = PFileInfo::DefaultDirPerms
);
PBoolean Remove();
static PBoolean Remove(
const PString & path
);
virtual PBoolean Open(
int scanMask = PFileInfo::AllFiles
);
virtual PBoolean Restart(
int scanMask = PFileInfo::AllFiles
);
PBoolean Next();
virtual void Close();
virtual PFilePathString GetEntryName() const;
virtual PBoolean IsSubDir() const;
virtual PBoolean GetInfo(
PFileInfo & info
) const;
protected:
// New functions for class
void Construct();
void Destruct()
{ Close(); PFilePathString::Destruct(); }
// Member variables
int scanMask;
// Include platform dependent part of class
#ifdef _WIN32
#include "msos/ptlib/pdirect.h"
#else
#include "unix/ptlib/pdirect.h"
#endif
};
#endif // PTLIB_DIRECTORY_H
// End Of File ///////////////////////////////////////////////////////////////
PDirectory::Change
PBoolean Change() const
Change the current working directory to the objects location.
PFileInfo::type
FileTypes type
File type for this file. Only one bit is set at a time here.
Definition: pdirect.h:94
PDirectory::Close
virtual void Close()
Close the directory during or after a file list scan.
PFileInfo::DefaultPerms
Owner read & write plus group and world read permissions.
Definition: pdirect.h:137
PContainer::Destruct
void Destruct()
Internal function called from container destructors.
PFileInfo::UserRead
File has owner read permission.
Definition: pdirect.h:133
PDirectory::Construct
void Construct()
PFileInfo::WorldRead
File has world read permission.
Definition: pdirect.h:121
PDirectory::operator=
PDirectory & operator=(const PString &pathname)
Set the directory to the specified path.
PDirectory::Next
PBoolean Next()
Move to the next file in the directory scan.
PDirectory::Exists
PBoolean Exists() const
Test for if the directory exists.
PDirectory::scanMask
int scanMask
Mask of file types that the directory scan will return.
Definition: pdirect.h:461
PFileInfo::hidden
PBoolean hidden
File is a hidden file.
Definition: pdirect.h:154
PTime
This class defines an absolute time and date.
Definition: ptime.h:53
PFileInfo::UserWrite
File has owner write permission.
Definition: pdirect.h:131
PFileInfo::accessed
PTime accessed
Time of last access to the file.
Definition: pdirect.h:107
PINLINE
#define PINLINE
Definition: object.h:127
PDirectory::GetEntryName
virtual PFilePathString GetEntryName() const
Get the name (without the volume or directory path) of the current entry in the directory scan...
PDirectory::Destruct
void Destruct()
Definition: pdirect.h:456
PFileInfo::AllFiles
Mask for all file types.
Definition: pdirect.h:90
PCaselessString
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
PFileInfo::DefaultDirPerms
Owner read & write & execute plus group and world read & exectute permissions.
Definition: pdirect.h:139
PFileInfo::FileTypes
FileTypes
All types that a particular file path may be.
Definition: pdirect.h:72
PFileInfo::Fifo
File path is a fifo (pipe) device.
Definition: pdirect.h:84
PFileInfo::GroupExecute
File has group execute permission.
Definition: pdirect.h:123
PDirectory::IsSubDir
virtual PBoolean IsSubDir() const
Determine if the directory entry currently being scanned is itself another directory entry...
PStringArray
This is an array collection class of PString objects.
Definition: pstring.h:2024
PDirectory::GetParent
PDirectory GetParent() const
Get the directory for the parent to the current directory.
PDirectory::GetVolumeSpace
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 con...
P_MAX_PATH
#define P_MAX_PATH
Definition: pdirect.h:52
PDirectory::Open
virtual PBoolean Open(int scanMask=PFileInfo::AllFiles)
Open the directory for scanning its list of files.
PBoolean
BOOL PBoolean
Definition: object.h:102
PDirectory
Class to represent a directory in the operating system file system.
Definition: pdirect.h:182
PFileInfo::AllPermissions
All possible permissions.
Definition: pdirect.h:135
PFileInfo::Permissions
Permissions
File access permissions for the file.
Definition: pdirect.h:115
PFileInfo::modified
PTime modified
Time of last modifiaction of the file.
Definition: pdirect.h:102
PFileInfo::WorldWrite
File has world write permission.
Definition: pdirect.h:119
PDirectory::Restart
virtual PBoolean Restart(int scanMask=PFileInfo::AllFiles)
Restart file list scan from the beginning of directory.
free
#define free(p)
Override of system call for memory check system.
Definition: object.h:864
PFileInfo::created
PTime created
Time of file creation of the file.
Definition: pdirect.h:99
PFileInfo::UnknownFileType
File path is of an unknown type.
Definition: pdirect.h:88
PFilePathString
PString PFilePathString
Definition: pdirect.h:53
PFileInfo::GroupWrite
File has group write permission.
Definition: pdirect.h:125
PDirectory::GetInfo
virtual PBoolean GetInfo(PFileInfo &info) const
Get file information on the current directory entry.
PFileInfo::SubDirectory
File path is a sub-directory.
Definition: pdirect.h:78
PString
The character string class.
Definition: pstring.h:108
PDirectory::GetRoot
PDirectory GetRoot() const
Get the root directory of a volume.
PFilePathString
Base string type for a file path.
Definition: filepath.h:48
PFileInfo::WorldExecute
File has world execute permission.
Definition: pdirect.h:117
PDirectory::Remove
PBoolean Remove()
Delete the directory.
PFileInfo::UserExecute
File has owner execute permission.
Definition: pdirect.h:129
PFileInfo::GroupRead
File has group read permission.
Definition: pdirect.h:127
PFileInfo::permissions
int permissions
A bit mask of all the file acces permissions.
Definition: pdirect.h:148
PDirectory::IsRoot
PBoolean IsRoot() const
Determine if the directory is the root directory of a volume.
PDirectory::IsSeparator
static PINLINE PBoolean IsSeparator(char ch)
Determine if the character ch is a directory path separator.
PFileInfo::size
PUInt64 size
Size of the file in bytes.
Definition: pdirect.h:112
PDirectory::GetPath
PStringArray GetPath() const
Get the directory path as an array of strings.
PFileInfo::SymbolicLink
File path is a symbolic link.
Definition: pdirect.h:76
PDirectory::PDirectory
PDirectory()
Create a directory object of the current working directory.
PDirectory::Create
PBoolean Create(int perm=PFileInfo::DefaultDirPerms) const
Create a new directory with the specified permissions.
PFileInfo::BlockDevice
File path is a block device name.
Definition: pdirect.h:82
PFileInfo::CharDevice
File path is a character device name.
Definition: pdirect.h:80
PFileInfo
Class containing the system information on a file path.
Definition: pdirect.h:63
PDirectory::GetVolume
PFilePathString GetVolume() const
Get the volume name that the directory is in.
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PFileInfo::SocketDevice
File path is a socket device.
Definition: pdirect.h:86
PFileInfo::RegularFile
Ordinary disk file.
Definition: pdirect.h:74