PTLib  Version 2.10.11
pdirect.h
Go to the documentation of this file.
1 /*
2  * pdirect.h
3  *
4  * File system directory class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
32  */
33 
34 
35 #ifndef PTLIB_DIRECTORY_H
36 #define PTLIB_DIRECTORY_H
37 
38 #ifdef P_USE_PRAGMA
39 #pragma interface
40 #endif
41 
42 #ifdef Fifo
43 #undef Fifo
44 #endif
45 
46 #ifdef _WIN32
47 #define PDIR_SEPARATOR '\\'
48 const PINDEX P_MAX_PATH = _MAX_PATH;
50 #else
51 #define PDIR_SEPARATOR '/'
52 #define P_MAX_PATH (_POSIX_PATH_MAX)
54 #endif
55 
57 // File System
58 
63 class PFileInfo : public PObject
64 {
65  PCLASSINFO(PFileInfo, PObject);
66 
67  public:
72  enum FileTypes {
80  CharDevice = 8,
82  BlockDevice = 16,
84  Fifo = 32,
86  SocketDevice = 64,
90  AllFiles = 0x1ff
91  };
92 
95 
100 
103 
108 
112  PUInt64 size;
113 
115  enum Permissions {
121  WorldRead = 4,
125  GroupWrite = 16,
127  GroupRead = 32,
129  UserExecute = 64,
131  UserWrite = 128,
133  UserRead = 256,
135  AllPermissions = 0x1ff,
140 
141  };
142 
149 
155 };
156 
157 
183 {
184  PCONTAINERINFO(PDirectory, PFilePathString);
185 
186  public:
189  PDirectory();
191 
196  PDirectory(
197  const char * cpathname
198  );
199 
204  PDirectory(
205  const PString & pathname
206  );
207 
211  const PString & pathname
212  );
213 
217  const char * cpathname
218  );
220 
230  PDirectory GetParent() const;
231 
242  PFilePathString GetVolume() const;
243 
249  PBoolean IsRoot() const;
250 
256  PDirectory GetRoot() const;
257 
262  PStringArray GetPath() const;
263 
271  char ch
272  );
273 
285  PInt64 & total,
286  PInt64 & free,
287  DWORD & clusterSize
288  ) const;
290 
298  PBoolean Exists() const;
299 
305  static PBoolean Exists(
306  const PString & path
307  );
308 
314  PBoolean Change() const;
315 
321  static PBoolean Change(
322  const PString & path
323  );
324 
331  int perm = PFileInfo::DefaultDirPerms // Permission on new directory.
332  ) const;
338  static PBoolean Create(
339  const PString & p,
340  int perm = PFileInfo::DefaultDirPerms
341  );
342 
348  PBoolean Remove();
349 
355  static PBoolean Remove(
356  const PString & path
357  );
359 
377  virtual PBoolean Open(
379  );
380 
395  virtual PBoolean Restart(
397  );
398 
410  PBoolean Next();
411 
413  virtual void Close();
414 
429  virtual PFilePathString GetEntryName() const;
430 
440  virtual PBoolean IsSubDir() const;
441 
447  virtual PBoolean GetInfo(
448  PFileInfo & info
449  ) const;
451 
452 
453  protected:
454  // New functions for class
455  void Construct();
456  void Destruct()
458 
459  // Member variables
461  int scanMask;
462 
463 // Include platform dependent part of class
464 #ifdef _WIN32
465 #include "msos/ptlib/pdirect.h"
466 #else
467 #include "unix/ptlib/pdirect.h"
468 #endif
469 
470 };
471 
472 
473 #endif // PTLIB_DIRECTORY_H
474 
475 
476 // End Of File ///////////////////////////////////////////////////////////////
PBoolean Change() const
Change the current working directory to the objects location.
FileTypes type
File type for this file. Only one bit is set at a time here.
Definition: pdirect.h:94
virtual void Close()
Close the directory during or after a file list scan.
Owner read & write plus group and world read permissions.
Definition: pdirect.h:137
void Destruct()
Internal function called from container destructors.
File has owner read permission.
Definition: pdirect.h:133
void Construct()
File has world read permission.
Definition: pdirect.h:121
PDirectory & operator=(const PString &pathname)
Set the directory to the specified path.
PBoolean Next()
Move to the next file in the directory scan.
PBoolean Exists() const
Test for if the directory exists.
int scanMask
Mask of file types that the directory scan will return.
Definition: pdirect.h:461
PBoolean hidden
File is a hidden file.
Definition: pdirect.h:154
This class defines an absolute time and date.
Definition: ptime.h:53
File has owner write permission.
Definition: pdirect.h:131
PTime accessed
Time of last access to the file.
Definition: pdirect.h:107
#define PINLINE
Definition: object.h:127
virtual PFilePathString GetEntryName() const
Get the name (without the volume or directory path) of the current entry in the directory scan...
void Destruct()
Definition: pdirect.h:456
Mask for all file types.
Definition: pdirect.h:90
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
Owner read & write & execute plus group and world read & exectute permissions.
Definition: pdirect.h:139
FileTypes
All types that a particular file path may be.
Definition: pdirect.h:72
File path is a fifo (pipe) device.
Definition: pdirect.h:84
File has group execute permission.
Definition: pdirect.h:123
virtual PBoolean IsSubDir() const
Determine if the directory entry currently being scanned is itself another directory entry...
This is an array collection class of PString objects.
Definition: pstring.h:2024
PDirectory GetParent() const
Get the directory for the parent to the current directory.
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...
#define P_MAX_PATH
Definition: pdirect.h:52
virtual PBoolean Open(int scanMask=PFileInfo::AllFiles)
Open the directory for scanning its list of files.
BOOL PBoolean
Definition: object.h:102
Class to represent a directory in the operating system file system.
Definition: pdirect.h:182
All possible permissions.
Definition: pdirect.h:135
Permissions
File access permissions for the file.
Definition: pdirect.h:115
PTime modified
Time of last modifiaction of the file.
Definition: pdirect.h:102
File has world write permission.
Definition: pdirect.h:119
virtual PBoolean Restart(int scanMask=PFileInfo::AllFiles)
Restart file list scan from the beginning of directory.
#define free(p)
Override of system call for memory check system.
Definition: object.h:864
PTime created
Time of file creation of the file.
Definition: pdirect.h:99
File path is of an unknown type.
Definition: pdirect.h:88
PString PFilePathString
Definition: pdirect.h:53
File has group write permission.
Definition: pdirect.h:125
virtual PBoolean GetInfo(PFileInfo &info) const
Get file information on the current directory entry.
File path is a sub-directory.
Definition: pdirect.h:78
The character string class.
Definition: pstring.h:108
PDirectory GetRoot() const
Get the root directory of a volume.
Base string type for a file path.
Definition: filepath.h:48
File has world execute permission.
Definition: pdirect.h:117
PBoolean Remove()
Delete the directory.
File has owner execute permission.
Definition: pdirect.h:129
File has group read permission.
Definition: pdirect.h:127
int permissions
A bit mask of all the file acces permissions.
Definition: pdirect.h:148
PBoolean IsRoot() const
Determine if the directory is the root directory of a volume.
static PINLINE PBoolean IsSeparator(char ch)
Determine if the character ch is a directory path separator.
PUInt64 size
Size of the file in bytes.
Definition: pdirect.h:112
PStringArray GetPath() const
Get the directory path as an array of strings.
File path is a symbolic link.
Definition: pdirect.h:76
PDirectory()
Create a directory object of the current working directory.
PBoolean Create(int perm=PFileInfo::DefaultDirPerms) const
Create a new directory with the specified permissions.
File path is a block device name.
Definition: pdirect.h:82
File path is a character device name.
Definition: pdirect.h:80
Class containing the system information on a file path.
Definition: pdirect.h:63
PFilePathString GetVolume() const
Get the volume name that the directory is in.
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
File path is a socket device.
Definition: pdirect.h:86
Ordinary disk file.
Definition: pdirect.h:74