]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filename.h
Ownerdrawn testing
[wxWidgets.git] / include / wx / filename.h
CommitLineData
df5ddbca 1/////////////////////////////////////////////////////////////////////////////
097ead30
VZ
2// Name: wx/filename.h
3// Purpose: wxFileName - encapsulates a file path
844f90fb 4// Author: Robert Roebling, Vadim Zeitlin
df5ddbca
RR
5// Modified by:
6// Created: 28.12.00
7// RCS-ID: $Id$
8// Copyright: (c) 2000 Robert Roebling
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_FILENAME_H_
13#define _WX_FILENAME_H_
14
15#ifdef __GNUG__
16 #pragma interface "filename.h"
17#endif
18
19#ifndef WX_PRECOMP
9e8d8607 20 #include "wx/string.h"
df5ddbca
RR
21#endif
22
9e8d8607
VZ
23/*
24 TODO:
25
26 1. support for drives under Windows
27 2. more file operations:
28 a) chmod()
29 b) [acm]time() - get and set
30 c) file size
31 d) file permissions with readable accessors for most common bits
32 such as IsReadable() &c
33 e) rename()?
34 3. SameFileAs() function to compare inodes under Unix
35 */
36
df5ddbca 37// ridiculously enough, this will replace DirExists with wxDirExists etc
ee66f092 38#include "wx/filefn.h"
df5ddbca 39
097ead30
VZ
40// ----------------------------------------------------------------------------
41// constants
42// ----------------------------------------------------------------------------
43
44// the various values for the path format: this mainly affects the path
45// separator but also whether or not the path has the drive part (as under
46// Windows)
df5ddbca
RR
47enum wxPathFormat
48{
844f90fb 49 wxPATH_NATIVE = 0, // the path format for the current platform
097ead30
VZ
50 wxPATH_UNIX,
51 wxPATH_MAC,
52 wxPATH_DOS,
ee66f092 53
097ead30
VZ
54 wxPATH_BEOS = wxPATH_UNIX,
55 wxPATH_WIN = wxPATH_DOS,
56 wxPATH_OS2 = wxPATH_DOS
57};
ee66f092 58
097ead30
VZ
59// the kind of normalization to do with the file name: these values can be
60// or'd together to perform several operations at once
61enum wxPathNormalize
62{
63 wxPATH_NORM_ENV_VARS = 0x0001, // replace env vars with their values
844f90fb 64 wxPATH_NORM_DOTS = 0x0002, // squeeze all .. and . and prepend cwd
097ead30 65 wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user
844f90fb
VZ
66 wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower
67 wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute
68 wxPATH_NORM_ALL = 0x001f
df5ddbca
RR
69};
70
097ead30
VZ
71// ----------------------------------------------------------------------------
72// wxFileName: encapsulates a file path
73// ----------------------------------------------------------------------------
74
df5ddbca
RR
75class WXDLLEXPORT wxFileName
76{
77public:
78 // constructors and assignment
844f90fb
VZ
79
80 // the usual stuff
81 wxFileName() { }
82 wxFileName( const wxFileName &filepath ) { Assign(filepath); }
83
84 // from a full filename: if it terminates with a '/', a directory path
85 // is contructed (the name will be empty), otherwise a file name and
86 // extension are extracted from it
87 wxFileName( const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE )
88 { Assign( fullpath, format ); }
89
90 // from a directory name and a file name
91 wxFileName(const wxString& path,
92 const wxString& name,
93 wxPathFormat format = wxPATH_NATIVE)
94 { Assign(path, name, format); }
95
96 // from a directory name, file base name and extension
97 wxFileName(const wxString& path,
98 const wxString& name,
99 const wxString& ext,
100 wxPathFormat format = wxPATH_NATIVE)
101 { Assign(path, name, ext, format); }
102
103 // assorted assignment operators
104
105 wxFileName& operator=(const wxFileName& filename)
106 { Assign(filename); return *this; }
107
108 wxFileName& operator=(const wxString& filename)
109 { Assign(filename); return *this; }
110
111 // the same for delayed initialization
112
113 // VZ: wouldn't it be better to call this Create() for consistency with
114 // all GUI classes? Personally, I like Set() more than Assign() too
115
116 void Assign(const wxFileName& filepath);
117 void Assign(const wxString& fullpath,
118 wxPathFormat format = wxPATH_NATIVE);
119 void Assign(const wxString& path,
120 const wxString& name,
121 wxPathFormat format = wxPATH_NATIVE);
122 void Assign(const wxString& path,
123 const wxString& name,
124 const wxString& ext,
125 wxPathFormat format = wxPATH_NATIVE);
126 void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE)
127 { Assign(dir, _T(""), format); }
128
129 // reset all components to default, uninitialized state
130 void Clear();
131
132 // static pseudo constructors
133 static wxFileName FileName(const wxString& file);
134 static wxFileName DirName(const wxString& dir);
135
136 // test for existence
137
138 // is the filename valid at all?
139 bool IsOk() const { return !m_dirs.IsEmpty() || !m_name.IsEmpty(); }
140
141 // does the file with this name exists?
df5ddbca 142 bool FileExists();
a35b27b1 143 static bool FileExists( const wxString &file );
097ead30 144
844f90fb 145 // does the directory with this name exists?
df5ddbca 146 bool DirExists();
a35b27b1 147 static bool DirExists( const wxString &dir );
097ead30 148
844f90fb
VZ
149 // VZ: also need: IsDirWritable(), IsFileExecutable() &c (TODO)
150
151 // various file/dir operations
152
153 // retrieve the value of the current working directory
df5ddbca 154 void AssignCwd();
a35b27b1 155 static wxString GetCwd();
097ead30 156
844f90fb 157 // change the current working directory
a35b27b1
RR
158 bool SetCwd();
159 static bool SetCwd( const wxString &cwd );
097ead30 160
844f90fb 161 // get the value of user home (Unix only mainly)
a35b27b1
RR
162 void AssignHomeDir();
163 static wxString GetHomeDir();
097ead30 164
844f90fb 165 // get a temp file name starting with thespecified prefix
df5ddbca 166 void AssignTempFileName( const wxString &prefix );
097ead30 167
844f90fb 168 // directory creation and removal
a35b27b1
RR
169 bool Mkdir( int perm = 0777 );
170 static bool Mkdir( const wxString &dir, int perm = 0777 );
097ead30 171
a35b27b1
RR
172 bool Rmdir();
173 static bool Rmdir( const wxString &dir );
097ead30 174
844f90fb
VZ
175 // operations on the path
176
177 // normalize the path: with the default flags value, the path will be
178 // made absolute, without any ".." and "." and all environment
179 // variables will be expanded in it
180 //
181 // this may be done using another (than current) value of cwd
182 bool Normalize(wxPathNormalize flags = wxPATH_NORM_ALL,
183 const wxString& cwd = wxEmptyString,
184 wxPathFormat format = wxPATH_NATIVE);
097ead30 185
df5ddbca 186 // Comparison
844f90fb
VZ
187
188 // uses the current platform settings
189 bool operator==(const wxFileName& filename) { return SameAs(filename); }
190 bool operator==(const wxString& filename)
191 { return *this == wxFileName(filename); }
192
193 // compares with the rules of this platform
194 bool SameAs(const wxFileName &filepath,
195 wxPathFormat format = wxPATH_NATIVE);
097ead30 196
df5ddbca 197 // Tests
844f90fb 198 static bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE );
df5ddbca
RR
199 bool IsRelative( wxPathFormat format = wxPATH_NATIVE );
200 bool IsAbsolute( wxPathFormat format = wxPATH_NATIVE );
844f90fb
VZ
201
202 // get the string of path separators for this format
203 static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE);
204
205 // is the char a path separator for this format?
206 static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE);
207
208 // FIXME: what exactly does this do?
df5ddbca 209 bool IsWild( wxPathFormat format = wxPATH_NATIVE );
097ead30 210
df5ddbca
RR
211 // Dir accessors
212 void AppendDir( const wxString &dir );
213 void PrependDir( const wxString &dir );
214 void InsertDir( int before, const wxString &dir );
215 void RemoveDir( int pos );
097ead30
VZ
216 size_t GetDirCount() const { return m_dirs.GetCount(); }
217
df5ddbca
RR
218 // Other accessors
219 void SetExt( const wxString &ext ) { m_ext = ext; }
220 wxString GetExt() const { return m_ext; }
221 bool HasExt() const { return !m_ext.IsEmpty(); }
097ead30 222
df5ddbca
RR
223 void SetName( const wxString &name ) { m_name = name; }
224 wxString GetName() const { return m_name; }
225 bool HasName() const { return !m_name.IsEmpty(); }
097ead30 226
7124df9b
VZ
227 // full name is the file name + extension (but without the path)
228 void SetFullName(const wxString& fullname);
844f90fb 229 wxString GetFullName() const;
097ead30 230
df5ddbca 231 const wxArrayString &GetDirs() const { return m_dirs; }
097ead30 232
844f90fb 233 // Construct path only - possibly with the trailing separator
7124df9b
VZ
234 wxString GetPath( bool add_separator = FALSE,
235 wxPathFormat format = wxPATH_NATIVE ) const;
097ead30 236
844f90fb
VZ
237 // more readable synonym
238 wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const
239 { return GetPath(TRUE /* add separator */, format); }
240
df5ddbca
RR
241 // Construct full path with name and ext
242 wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const;
097ead30 243
9e8d8607
VZ
244 // various helpers
245
246 // get the canonical path format for this platform
df5ddbca 247 static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE );
097ead30 248
9e8d8607
VZ
249 // split a fullpath into path, (base) name and ext (all of the pointers
250 // can be NULL)
251 static void SplitPath(const wxString& fullpath,
252 wxString *path,
253 wxString *name,
254 wxString *ext,
255 wxPathFormat format = wxPATH_NATIVE);
256
df5ddbca 257private:
844f90fb 258 // the path components of the file
df5ddbca 259 wxArrayString m_dirs;
844f90fb
VZ
260
261 // the file name and extension (empty for directories)
262 wxString m_name,
263 m_ext;
df5ddbca
RR
264};
265
097ead30 266#endif // _WX_FILENAME_H_
df5ddbca 267