00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _PDIRECTORY
00036 #define _PDIRECTORY
00037
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041
00042 #ifdef Fifo
00043 #undef Fifo
00044 #endif
00045
00046 #ifdef _WIN32
00047 #define PDIR_SEPARATOR '\\'
00048 const PINDEX P_MAX_PATH = _MAX_PATH;
00049 typedef PCaselessString PFilePathString;
00050 #else
00051 #define PDIR_SEPARATOR '/'
00052 #define P_MAX_PATH (_POSIX_PATH_MAX)
00053 typedef PString PFilePathString;
00054 #endif
00055
00057
00058
00063 class PFileInfo : public PObject
00064 {
00065 PCLASSINFO(PFileInfo, PObject);
00066
00067 public:
00072 enum FileTypes {
00074 RegularFile = 1,
00076 SymbolicLink = 2,
00078 SubDirectory = 4,
00080 CharDevice = 8,
00082 BlockDevice = 16,
00084 Fifo = 32,
00086 SocketDevice = 64,
00088 UnknownFileType = 256,
00090 AllFiles = 0x1ff
00091 };
00092
00094 FileTypes type;
00095
00099 PTime created;
00100
00102 PTime modified;
00103
00107 PTime accessed;
00108
00112 PUInt64 size;
00113
00115 enum Permissions {
00117 WorldExecute = 1,
00119 WorldWrite = 2,
00121 WorldRead = 4,
00123 GroupExecute = 8,
00125 GroupWrite = 16,
00127 GroupRead = 32,
00129 UserExecute = 64,
00131 UserWrite = 128,
00133 UserRead = 256,
00135 AllPermissions = 0x1ff,
00137 DefaultPerms = UserRead|UserWrite|GroupRead|WorldRead,
00139 DefaultDirPerms = DefaultPerms|UserExecute|GroupExecute|WorldExecute
00140
00141 };
00142
00148 int permissions;
00149
00154 PBoolean hidden;
00155 };
00156
00157
00182 class PDirectory : public PFilePathString
00183 {
00184 PCONTAINERINFO(PDirectory, PFilePathString);
00185
00186 public:
00189
00190 PDirectory();
00191
00196 PDirectory(
00197 const char * cpathname
00198 );
00199
00204 PDirectory(
00205 const PString & pathname
00206 );
00207
00210 PDirectory & operator=(
00211 const PString & pathname
00212 );
00213
00216 PDirectory & operator=(
00217 const char * cpathname
00218 );
00220
00230 PDirectory GetParent() const;
00231
00242 PFilePathString GetVolume() const;
00243
00249 PBoolean IsRoot() const;
00250
00256 PDirectory GetRoot() const;
00257
00262 PStringArray GetPath() const;
00263
00270 PINLINE static PBoolean IsSeparator(
00271 char ch
00272 );
00273
00284 PBoolean GetVolumeSpace(
00285 PInt64 & total,
00286 PInt64 & free,
00287 DWORD & clusterSize
00288 ) const;
00290
00298 PBoolean Exists() const;
00299
00305 static PBoolean Exists(
00306 const PString & path
00307 );
00308
00314 PBoolean Change() const;
00315
00321 static PBoolean Change(
00322 const PString & path
00323 );
00324
00330 PBoolean Create(
00331 int perm = PFileInfo::DefaultDirPerms
00332 ) const;
00338 static PBoolean Create(
00339 const PString & p,
00340 int perm = PFileInfo::DefaultDirPerms
00341 );
00342
00348 PBoolean Remove();
00349
00355 static PBoolean Remove(
00356 const PString & path
00357 );
00359
00377 virtual PBoolean Open(
00378 int scanMask = PFileInfo::AllFiles
00379 );
00380
00395 virtual PBoolean Restart(
00396 int scanMask = PFileInfo::AllFiles
00397 );
00398
00410 PBoolean Next();
00411
00413 virtual void Close();
00414
00429 virtual PFilePathString GetEntryName() const;
00430
00440 virtual PBoolean IsSubDir() const;
00441
00447 virtual PBoolean GetInfo(
00448 PFileInfo & info
00449 ) const;
00451
00452
00453 protected:
00454
00455 void Construct();
00456 void Destruct()
00457 { Close(); PFilePathString::Destruct(); }
00458
00459
00461 int scanMask;
00462
00463
00464 #ifdef _WIN32
00465 #include "msos/ptlib/pdirect.h"
00466 #else
00467 #include "unix/ptlib/pdirect.h"
00468 #endif
00469
00470 };
00471
00472 #endif
00473
00474