PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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: 24177 $
30 * $Author: rjongbloed $
31 * $Date: 2010-04-05 21:52:04 +1000 (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;
49 typedef PCaselessString PFilePathString;
50 #else
51 #define PDIR_SEPARATOR '/'
52 #define P_MAX_PATH (_POSIX_PATH_MAX)
53 typedef PString PFilePathString;
54 #endif
55
57 // File System
58
63 class PFileInfo : public PObject
64 {
65 PCLASSINFO(PFileInfo, PObject);
66
67 public:
72 enum FileTypes {
74 RegularFile = 1,
76 SymbolicLink = 2,
78 SubDirectory = 4,
80 CharDevice = 8,
82 BlockDevice = 16,
84 Fifo = 32,
86 SocketDevice = 64,
88 UnknownFileType = 256,
90 AllFiles = 0x1ff
91 };
92
94 FileTypes type;
95
99 PTime created;
100
102 PTime modified;
103
107 PTime accessed;
108
112 PUInt64 size;
113
115 enum Permissions {
117 WorldExecute = 1,
119 WorldWrite = 2,
121 WorldRead = 4,
123 GroupExecute = 8,
125 GroupWrite = 16,
127 GroupRead = 32,
129 UserExecute = 64,
131 UserWrite = 128,
133 UserRead = 256,
135 AllPermissions = 0x1ff,
137 DefaultPerms = UserRead|UserWrite|GroupRead|WorldRead,
139 DefaultDirPerms = DefaultPerms|UserExecute|GroupExecute|WorldExecute
140
141 };
142
148 int permissions;
149
154 PBoolean hidden;
155 };
156
157
182 class PDirectory : public PFilePathString
183 {
184 PCONTAINERINFO(PDirectory, PFilePathString);
185
186 public:
189
190 PDirectory();
191
196 PDirectory(
197 const char * cpathname
198 );
199
204 PDirectory(
205 const PString & pathname
206 );
207
210 PDirectory & operator=(
211 const PString & pathname
212 );
213
216 PDirectory & operator=(
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
270 PINLINE static PBoolean IsSeparator(
271 char ch
272 );
273
284 PBoolean GetVolumeSpace(
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
330 PBoolean Create(
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(
378 int scanMask = PFileInfo::AllFiles
379 );
380
395 virtual PBoolean Restart(
396 int scanMask = PFileInfo::AllFiles
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()
457 { Close(); PFilePathString::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 ///////////////////////////////////////////////////////////////