]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filename.h
added generic implementation and documentation for wxFindReplaceDialog
[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"
ce16e5d7 39#include "wx/datetime.h"
df5ddbca 40
097ead30
VZ
41// ----------------------------------------------------------------------------
42// constants
43// ----------------------------------------------------------------------------
44
45// the various values for the path format: this mainly affects the path
46// separator but also whether or not the path has the drive part (as under
47// Windows)
df5ddbca
RR
48enum wxPathFormat
49{
844f90fb 50 wxPATH_NATIVE = 0, // the path format for the current platform
097ead30
VZ
51 wxPATH_UNIX,
52 wxPATH_MAC,
53 wxPATH_DOS,
ee66f092 54
097ead30
VZ
55 wxPATH_BEOS = wxPATH_UNIX,
56 wxPATH_WIN = wxPATH_DOS,
57 wxPATH_OS2 = wxPATH_DOS
58};
ee66f092 59
097ead30
VZ
60// the kind of normalization to do with the file name: these values can be
61// or'd together to perform several operations at once
62enum wxPathNormalize
63{
64 wxPATH_NORM_ENV_VARS = 0x0001, // replace env vars with their values
844f90fb 65 wxPATH_NORM_DOTS = 0x0002, // squeeze all .. and . and prepend cwd
097ead30 66 wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user
844f90fb
VZ
67 wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower
68 wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute
9e9b65c1
JS
69 wxPATH_NORM_LONG = 0x0020, // make the path the long form
70 wxPATH_NORM_ALL = 0x003f
df5ddbca
RR
71};
72
097ead30
VZ
73// ----------------------------------------------------------------------------
74// wxFileName: encapsulates a file path
75// ----------------------------------------------------------------------------
76
df5ddbca
RR
77class WXDLLEXPORT wxFileName
78{
79public:
80 // constructors and assignment
844f90fb
VZ
81
82 // the usual stuff
83 wxFileName() { }
84 wxFileName( const wxFileName &filepath ) { Assign(filepath); }
85
86 // from a full filename: if it terminates with a '/', a directory path
87 // is contructed (the name will be empty), otherwise a file name and
88 // extension are extracted from it
89 wxFileName( const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE )
90 { Assign( fullpath, format ); }
91
92 // from a directory name and a file name
93 wxFileName(const wxString& path,
94 const wxString& name,
95 wxPathFormat format = wxPATH_NATIVE)
96 { Assign(path, name, format); }
97
98 // from a directory name, file base name and extension
99 wxFileName(const wxString& path,
100 const wxString& name,
101 const wxString& ext,
102 wxPathFormat format = wxPATH_NATIVE)
103 { Assign(path, name, ext, format); }
104
844f90fb
VZ
105 // the same for delayed initialization
106
107 // VZ: wouldn't it be better to call this Create() for consistency with
108 // all GUI classes? Personally, I like Set() more than Assign() too
109
110 void Assign(const wxFileName& filepath);
111 void Assign(const wxString& fullpath,
112 wxPathFormat format = wxPATH_NATIVE);
113 void Assign(const wxString& path,
114 const wxString& name,
115 wxPathFormat format = wxPATH_NATIVE);
116 void Assign(const wxString& path,
117 const wxString& name,
118 const wxString& ext,
119 wxPathFormat format = wxPATH_NATIVE);
120 void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE)
121 { Assign(dir, _T(""), format); }
122
788722ac
JS
123 // assorted assignment operators
124
125 wxFileName& operator=(const wxFileName& filename)
126 { Assign(filename); return *this; }
127
128 wxFileName& operator=(const wxString& filename)
129 { Assign(filename); return *this; }
130
844f90fb
VZ
131 // reset all components to default, uninitialized state
132 void Clear();
133
134 // static pseudo constructors
135 static wxFileName FileName(const wxString& file);
136 static wxFileName DirName(const wxString& dir);
137
138 // test for existence
139
140 // is the filename valid at all?
141 bool IsOk() const { return !m_dirs.IsEmpty() || !m_name.IsEmpty(); }
142
143 // does the file with this name exists?
df5ddbca 144 bool FileExists();
a35b27b1 145 static bool FileExists( const wxString &file );
097ead30 146
844f90fb 147 // does the directory with this name exists?
df5ddbca 148 bool DirExists();
a35b27b1 149 static bool DirExists( const wxString &dir );
097ead30 150
ce16e5d7
RR
151 // Well, get modification time with sec resolution
152 wxDateTime GetModificationTime();
153
844f90fb
VZ
154 // VZ: also need: IsDirWritable(), IsFileExecutable() &c (TODO)
155
156 // various file/dir operations
157
158 // retrieve the value of the current working directory
df5ddbca 159 void AssignCwd();
a35b27b1 160 static wxString GetCwd();
097ead30 161
844f90fb 162 // change the current working directory
a35b27b1
RR
163 bool SetCwd();
164 static bool SetCwd( const wxString &cwd );
097ead30 165
844f90fb 166 // get the value of user home (Unix only mainly)
a35b27b1
RR
167 void AssignHomeDir();
168 static wxString GetHomeDir();
097ead30 169
844f90fb 170 // get a temp file name starting with thespecified prefix
df5ddbca 171 void AssignTempFileName( const wxString &prefix );
097ead30 172
f0ce3409
JS
173 // directory creation and removal.
174 // if full is TRUE, will try to make each directory in the path.
175 bool Mkdir( int perm = 0777, bool full = FALSE);
176 static bool Mkdir( const wxString &dir, int perm = 0777, bool full = FALSE );
097ead30 177
a35b27b1
RR
178 bool Rmdir();
179 static bool Rmdir( const wxString &dir );
097ead30 180
844f90fb
VZ
181 // operations on the path
182
183 // normalize the path: with the default flags value, the path will be
184 // made absolute, without any ".." and "." and all environment
185 // variables will be expanded in it
186 //
187 // this may be done using another (than current) value of cwd
188 bool Normalize(wxPathNormalize flags = wxPATH_NORM_ALL,
189 const wxString& cwd = wxEmptyString,
190 wxPathFormat format = wxPATH_NATIVE);
097ead30 191
df5ddbca 192 // Comparison
844f90fb 193
788722ac
JS
194 // compares with the rules of this platform
195 bool SameAs(const wxFileName &filepath,
196 wxPathFormat format = wxPATH_NATIVE);
197
844f90fb
VZ
198 // uses the current platform settings
199 bool operator==(const wxFileName& filename) { return SameAs(filename); }
200 bool operator==(const wxString& filename)
201 { return *this == wxFileName(filename); }
202
df5ddbca 203 // Tests
844f90fb 204 static bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE );
df5ddbca
RR
205 bool IsRelative( wxPathFormat format = wxPATH_NATIVE );
206 bool IsAbsolute( wxPathFormat format = wxPATH_NATIVE );
844f90fb
VZ
207
208 // get the string of path separators for this format
209 static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE);
210
211 // is the char a path separator for this format?
212 static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE);
213
214 // FIXME: what exactly does this do?
df5ddbca 215 bool IsWild( wxPathFormat format = wxPATH_NATIVE );
097ead30 216
df5ddbca
RR
217 // Dir accessors
218 void AppendDir( const wxString &dir );
219 void PrependDir( const wxString &dir );
220 void InsertDir( int before, const wxString &dir );
221 void RemoveDir( int pos );
097ead30
VZ
222 size_t GetDirCount() const { return m_dirs.GetCount(); }
223
df5ddbca
RR
224 // Other accessors
225 void SetExt( const wxString &ext ) { m_ext = ext; }
226 wxString GetExt() const { return m_ext; }
227 bool HasExt() const { return !m_ext.IsEmpty(); }
097ead30 228
df5ddbca
RR
229 void SetName( const wxString &name ) { m_name = name; }
230 wxString GetName() const { return m_name; }
231 bool HasName() const { return !m_name.IsEmpty(); }
097ead30 232
7124df9b
VZ
233 // full name is the file name + extension (but without the path)
234 void SetFullName(const wxString& fullname);
844f90fb 235 wxString GetFullName() const;
097ead30 236
df5ddbca 237 const wxArrayString &GetDirs() const { return m_dirs; }
097ead30 238
844f90fb 239 // Construct path only - possibly with the trailing separator
7124df9b
VZ
240 wxString GetPath( bool add_separator = FALSE,
241 wxPathFormat format = wxPATH_NATIVE ) const;
097ead30 242
844f90fb
VZ
243 // more readable synonym
244 wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const
245 { return GetPath(TRUE /* add separator */, format); }
246
df5ddbca
RR
247 // Construct full path with name and ext
248 wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const;
097ead30 249
9e9b65c1
JS
250 // Return the short form of the path (returns identity on non-Windows platforms)
251 wxString GetShortPath() const;
252
253 // Return the long form of the path (returns identity on non-Windows platforms)
254 wxString GetLongPath() const;
255
9e8d8607
VZ
256 // various helpers
257
258 // get the canonical path format for this platform
df5ddbca 259 static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE );
097ead30 260
9e8d8607
VZ
261 // split a fullpath into path, (base) name and ext (all of the pointers
262 // can be NULL)
263 static void SplitPath(const wxString& fullpath,
264 wxString *path,
265 wxString *name,
266 wxString *ext,
267 wxPathFormat format = wxPATH_NATIVE);
268
df5ddbca 269private:
844f90fb 270 // the path components of the file
df5ddbca 271 wxArrayString m_dirs;
844f90fb
VZ
272
273 // the file name and extension (empty for directories)
274 wxString m_name,
275 m_ext;
df5ddbca
RR
276};
277
097ead30 278#endif // _WX_FILENAME_H_
df5ddbca 279