PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
filepath.h
Go to the documentation of this file.
1 /*
2  * filepath.h
3  *
4  * File system path string abstraction 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 
30 #ifndef PTLIB_FILEPATH_H
31 #define PTLIB_FILEPATH_H
32 
33 #ifdef P_USE_PRAGMA
34 #pragma interface
35 #endif
36 
37 
38 #ifdef DOC_PLUS_PLUS
39 
44 class PFilePathString : public PString { };
45 #endif
46 
47 
49 // File Specification
50 
61 class PFilePath : public PFilePathString
62 {
63  PCLASSINFO(PFilePath, PFilePathString);
64 
65  public:
70  PFilePath();
71 
84  PFilePath(
85  const char * cstr
86  );
87 
100  PFilePath(
101  const PString & str
102  );
103 
106  PFilePath(
107  const PFilePath & path
108  );
109 
115  PFilePath(
116  const char * prefix,
117  const char * dir,
118  const char * suffix = NULL
119  );
120 
124  const PFilePath & path
125  );
139  const PString & str
140  );
154  const char * cstr
155  );
157 
166  const PString & str
167  );
168 
179  const char * cstr
180  );
181 
192  char ch // Character to concatenate.
193  );
195 
206  PFilePathString GetVolume() const;
207 
216  PFilePathString GetPath() const;
217 
224  PFilePathString GetTitle() const;
225 
237  PFilePathString GetType() const;
238 
249 
262  PDirectory GetDirectory() const;
263 
267  void SetType(
268  const PFilePathString & type
269  );
271 
279  static bool IsValid(
280  char c
281  );
282 
288  static bool IsValid(
289  const PString & str
290  );
291 
296  static PFilePathString Sanitise(
297  const PString & str,
298  const PString & extra = PString::Empty(),
299  char substitute = '_'
300  );
301 
304  static bool IsAbsolutePath(
305  const PString & path
306  );
308 
309  // Internal function to take partial path and make a full canonical path from it.
310  static PFilePathString Canonicalise(const PFilePathString & path, bool isDirectory);
311 
312  protected:
313  virtual void AssignContents(const PContainer & cont);
314 
315 
316 // Include platform dependent part of class
317 #ifdef _WIN32
318 #include "msos/ptlib/filepath.h"
319 #else
320 #include "unix/ptlib/filepath.h"
321 #endif
322 };
323 
324 
325 #endif // PTLIB_FILEPATH_H
326 
327 
328 // End Of File ///////////////////////////////////////////////////////////////
static PFilePathString Sanitise(const PString &str, const PString &extra=PString::Empty(), char substitute= '_')
Sanitise the string to be a legal filename.
PFilePathString GetFileName() const
Get the actual directory entry name component of the full file specification.
PFilePathString GetTitle() const
Get the title component of the full file path description, eg for the DOS file "C:\SRC\PWLIB\FRED.DAT" this would be "FRED".
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
PFilePathString GetVolume() const
Get the drive/volume name component of the full file path description.
PFilePath & operator=(const PFilePath &path)
Change the file path description to the specified file name.
PDirectory GetDirectory() const
Get the the directory that the file is contained in.
PFilePath & operator+=(const PString &str)
Concatenate a string to the file path, modifiying that path.
Class to represent a directory in the operating system file system.
Definition: pdirect.h:173
PFilePath()
Create an empty file path description.
void SetType(const PFilePathString &type)
Set the type component of the full file path description, eg for the DOS file "C:\SRC\PWLIB\FRED.DAT" would become "C:\SRC\PWLIB\FRED.TXT".
static PFilePathString Canonicalise(const PFilePathString &path, bool isDirectory)
The character string class.
Definition: pstring.h:108
static bool IsValid(char c)
Test if the character is valid in a filename.
Base string type for a file path.
Definition: filepath.h:44
virtual void AssignContents(const PContainer &cont)
Copy the container contents.
Abstract class to embody the base functionality of a container.
Definition: contain.h:99
PFilePathString GetType() const
Get the file type of the file.
static const PString & Empty()
Return an empty string.
static bool IsAbsolutePath(const PString &path)
Test if path is an absolute path or relative path.
PFilePathString GetPath() const
Get the directory path component of the full file path description.