PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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: 31682 $
30  * $Author: rjongbloed $
31  * $Date: 2014-04-05 11:14:56 +1100 (Sat, 05 Apr 2014) $
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 
43 
44 
45 #ifdef Fifo
46 #undef Fifo
47 #endif
48 
49 #ifdef _WIN32
50 #define PDIR_SEPARATOR '\\'
51 #define PPATH_SEPARATOR ';' // As used in PATH environment variable
52 const PINDEX P_MAX_PATH = _MAX_PATH;
54 #else
55 #define PDIR_SEPARATOR '/'
56 #define PPATH_SEPARATOR ':' // As used in PATH environment variable
57 #define P_MAX_PATH (_POSIX_PATH_MAX)
59 #endif
60 
61 
63 // File System
64 
69 class PFileInfo : public PObject
70 {
71  PCLASSINFO(PFileInfo, PObject);
72 
73  public:
78  P_DECLARE_BITWISE_ENUM_EX(FileTypes, 10,
79  (
80  NoFileType, // Should not happen!
81 
82  RegularFile,
83  SymbolicLink,
84  SubDirectory,
85  ParentDirectory,
86  CurrentDirectory,
87  CharDevice,
88  BlockDevice,
89  Fifo,
90  SocketDevice,
91  UnknownFileType
92  ),
93  AllFiles = 0x3ff,
94  DefaultSearch = RegularFile | SymbolicLink | SubDirectory
95  );
96 
98  FileTypes type;
99 
104 
107 
112 
116  PUInt64 size;
117 
119  P_DECLARE_BITWISE_ENUM_EX(Permissions,9,
120  (
121  // Note the following bits are as per unixish / C standard lib values, do not change!
122  NoPermissions,
123  WorldExecute,
124  WorldWrite,
125  WorldRead,
126  GroupExecute,
127  GroupWrite,
128  GroupRead,
129  UserExecute,
130  UserWrite,
131  UserRead
132  ),
133  AllPermissions = 0x1ff,
134  DefaultPerms = UserRead|UserWrite|GroupRead|WorldRead,
135  DefaultDirPerms = DefaultPerms|UserExecute|GroupExecute|WorldExecute
136  );
137 
143  Permissions permissions;
144 
149  bool hidden;
150 };
151 
152 
178 {
179  PCONTAINERINFO(PDirectory, PFilePathString);
180 
181  public:
184 
185  PDirectory();
186 
191  PDirectory(
192  const char * cpathname
193  );
194 
199  PDirectory(
200  const PString & pathname
201  );
202 
206  const PString & pathname
207  );
208 
212  const char * cpathname
213  );
215 
225  PDirectory GetParent() const;
226 
237  PFilePathString GetVolume() const;
238 
244  bool IsRoot() const;
245 
251  PDirectory GetRoot() const;
252 
257  PStringArray GetPath() const;
258 
265  PINLINE static bool IsSeparator(
266  char ch
267  );
268 
279  bool GetVolumeSpace(
280  PInt64 & total,
281  PInt64 & free,
282  DWORD & clusterSize
283  ) const;
285 
293  bool Exists() const;
294 
300  static bool Exists(
301  const PString & path
302  );
303 
309  bool Change() const;
310 
316  static bool Change(
317  const PString & path
318  );
319 
325  bool Create(
326  int perm = PFileInfo::DefaultDirPerms, // Permission on new directory.
327  bool recurse = false
328  ) const;
334  static bool Create(
335  const PString & p,
336  int perm = PFileInfo::DefaultDirPerms, // Permission on new directory.
337  bool recurse = false
338  );
339 
345  bool Remove();
346 
352  static bool Remove(
353  const PString & path
354  );
356 
374  virtual bool Open(
375  PFileInfo::FileTypes scanMask = PFileInfo::DefaultSearch
376  );
377 
392  virtual bool Restart(
393  PFileInfo::FileTypes scanMask = PFileInfo::DefaultSearch
394  );
395 
407  virtual bool Next();
408 
410  virtual void Close();
411 
426  virtual PFilePathString GetEntryName() const;
427 
437  virtual bool IsSubDir() const;
438 
444  virtual bool GetInfo(
445  PFileInfo & info
446  ) const;
448 
449 
450  protected:
451  // New functions for class
452  void Construct();
453  void Destruct()
455 
456  // Member variables
458  PFileInfo::FileTypes m_scanMask;
459 
460 // Include platform dependent part of class
461 #ifdef _WIN32
462 #include "msos/ptlib/pdirect.h"
463 #else
464 #include "unix/ptlib/pdirect.h"
465 #endif
466 
467 };
468 
469 
470 #endif // PTLIB_DIRECTORY_H
471 
472 
473 // End Of File ///////////////////////////////////////////////////////////////