]>
Commit | Line | Data |
---|---|---|
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 | |
65571936 | 9 | // Licence: wxWindows licence |
df5ddbca RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_FILENAME_H_ | |
13 | #define _WX_FILENAME_H_ | |
14 | ||
9e8d8607 VZ |
15 | /* |
16 | TODO: | |
17 | ||
18 | 1. support for drives under Windows | |
19 | 2. more file operations: | |
20 | a) chmod() | |
21 | b) [acm]time() - get and set | |
3ff07edb | 22 | c) rename()? |
9e8d8607 VZ |
23 | 3. SameFileAs() function to compare inodes under Unix |
24 | */ | |
25 | ||
20ceebaa | 26 | #include "wx/arrstr.h" |
ee66f092 | 27 | #include "wx/filefn.h" |
ce16e5d7 | 28 | #include "wx/datetime.h" |
98080d5c | 29 | #include "wx/intl.h" |
8e16c3f2 | 30 | #include "wx/longlong.h" |
a18d02ec | 31 | #include "wx/file.h" |
df5ddbca | 32 | |
68351053 | 33 | #if wxUSE_FILE |
b5dbe15d | 34 | class WXDLLIMPEXP_FWD_BASE wxFile; |
68351053 | 35 | #endif |
df22f860 | 36 | |
b70a2866 | 37 | #if wxUSE_FFILE |
b5dbe15d | 38 | class WXDLLIMPEXP_FWD_BASE wxFFile; |
b70a2866 MW |
39 | #endif |
40 | ||
35c2aa4f VZ |
41 | // this symbol is defined for the platforms where file systems use volumes in |
42 | // paths | |
d98a58c5 | 43 | #if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__) |
35c2aa4f VZ |
44 | #define wxHAS_FILESYSTEM_VOLUMES |
45 | #endif | |
46 | ||
097ead30 VZ |
47 | // ---------------------------------------------------------------------------- |
48 | // constants | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | // the various values for the path format: this mainly affects the path | |
52 | // separator but also whether or not the path has the drive part (as under | |
53 | // Windows) | |
df5ddbca RR |
54 | enum wxPathFormat |
55 | { | |
844f90fb | 56 | wxPATH_NATIVE = 0, // the path format for the current platform |
097ead30 | 57 | wxPATH_UNIX, |
f363e05c | 58 | wxPATH_BEOS = wxPATH_UNIX, |
097ead30 VZ |
59 | wxPATH_MAC, |
60 | wxPATH_DOS, | |
f363e05c VZ |
61 | wxPATH_WIN = wxPATH_DOS, |
62 | wxPATH_OS2 = wxPATH_DOS, | |
3c621059 | 63 | wxPATH_VMS, |
ee66f092 | 64 | |
f363e05c | 65 | wxPATH_MAX // Not a valid value for specifying path format |
097ead30 | 66 | }; |
ee66f092 | 67 | |
2febffba | 68 | // different conventions that may be used with GetHumanReadableSize() |
b2edb8f3 VZ |
69 | enum wxSizeConvention |
70 | { | |
2febffba FM |
71 | wxSIZE_CONV_TRADITIONAL, // 1024 bytes = 1 KB |
72 | wxSIZE_CONV_IEC, // 1024 bytes = 1 KiB | |
73 | wxSIZE_CONV_SI // 1000 bytes = 1 KB | |
b2edb8f3 VZ |
74 | }; |
75 | ||
097ead30 VZ |
76 | // the kind of normalization to do with the file name: these values can be |
77 | // or'd together to perform several operations at once | |
78 | enum wxPathNormalize | |
79 | { | |
80 | wxPATH_NORM_ENV_VARS = 0x0001, // replace env vars with their values | |
31eacdaf | 81 | wxPATH_NORM_DOTS = 0x0002, // squeeze all .. and . |
097ead30 | 82 | wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user |
844f90fb VZ |
83 | wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower |
84 | wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute | |
9e9b65c1 | 85 | wxPATH_NORM_LONG = 0x0020, // make the path the long form |
21f60945 JS |
86 | wxPATH_NORM_SHORTCUT = 0x0040, // resolve the shortcut, if it is a shortcut |
87 | wxPATH_NORM_ALL = 0x00ff & ~wxPATH_NORM_CASE | |
df5ddbca RR |
88 | }; |
89 | ||
33b97389 VZ |
90 | // what exactly should GetPath() return? |
91 | enum | |
92 | { | |
35c2aa4f | 93 | wxPATH_NO_SEPARATOR = 0x0000, // for symmetry with wxPATH_GET_SEPARATOR |
33b97389 VZ |
94 | wxPATH_GET_VOLUME = 0x0001, // include the volume if applicable |
95 | wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator | |
96 | }; | |
97 | ||
110c5094 | 98 | // Mkdir flags |
1527281e VZ |
99 | enum |
100 | { | |
101 | wxPATH_MKDIR_FULL = 0x0001 // create directories recursively | |
102 | }; | |
103 | ||
110c5094 VZ |
104 | // Rmdir flags |
105 | enum | |
106 | { | |
107 | wxPATH_RMDIR_FULL = 0x0001, // delete with subdirectories if empty | |
108 | wxPATH_RMDIR_RECURSIVE = 0x0002 // delete all recursively (dangerous!) | |
109 | }; | |
110 | ||
c50db847 VZ |
111 | // FileExists flags |
112 | enum | |
113 | { | |
114 | wxFILE_EXISTS_REGULAR = 0x0001, // check for existence of a regular file | |
115 | wxFILE_EXISTS_DIR = 0x0002, // check for existence of a directory | |
116 | wxFILE_EXISTS_SYMLINK = 0x0004, // check for existence of a symbolic link | |
117 | wxFILE_EXISTS_DEVICE = 0x0008, // check for existence of a device | |
118 | wxFILE_EXISTS_FIFO = 0x0016, // check for existence of a FIFO | |
119 | wxFILE_EXISTS_SOCKET = 0x0032, // check for existence of a socket | |
120 | // gap for future types | |
121 | wxFILE_EXISTS_ANY = 0x0FFF, // check for existence of anything | |
122 | wxFILE_EXISTS_NO_FOLLOW = 0x1000 // don't dereference a contained symlink | |
123 | }; | |
124 | ||
bd08f2f7 | 125 | #if wxUSE_LONGLONG |
98080d5c | 126 | // error code of wxFileName::GetSize() |
060668a1 | 127 | extern WXDLLIMPEXP_DATA_BASE(const wxULongLong) wxInvalidSize; |
bd08f2f7 | 128 | #endif // wxUSE_LONGLONG |
98080d5c JS |
129 | |
130 | ||
3ff07edb | 131 | |
097ead30 VZ |
132 | // ---------------------------------------------------------------------------- |
133 | // wxFileName: encapsulates a file path | |
134 | // ---------------------------------------------------------------------------- | |
135 | ||
bddd7a8d | 136 | class WXDLLIMPEXP_BASE wxFileName |
df5ddbca RR |
137 | { |
138 | public: | |
139 | // constructors and assignment | |
844f90fb VZ |
140 | |
141 | // the usual stuff | |
fb969475 | 142 | wxFileName() { Clear(); } |
520200fd | 143 | wxFileName(const wxFileName& filepath) { Assign(filepath); } |
844f90fb VZ |
144 | |
145 | // from a full filename: if it terminates with a '/', a directory path | |
146 | // is contructed (the name will be empty), otherwise a file name and | |
147 | // extension are extracted from it | |
148 | wxFileName( const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE ) | |
c063adeb | 149 | { Assign( fullpath, format ); m_dontFollowLinks = false; } |
844f90fb VZ |
150 | |
151 | // from a directory name and a file name | |
152 | wxFileName(const wxString& path, | |
153 | const wxString& name, | |
154 | wxPathFormat format = wxPATH_NATIVE) | |
c063adeb | 155 | { Assign(path, name, format); m_dontFollowLinks = false; } |
844f90fb | 156 | |
81f25632 VZ |
157 | // from a volume, directory name, file base name and extension |
158 | wxFileName(const wxString& volume, | |
159 | const wxString& path, | |
160 | const wxString& name, | |
161 | const wxString& ext, | |
162 | wxPathFormat format = wxPATH_NATIVE) | |
c063adeb | 163 | { Assign(volume, path, name, ext, format); m_dontFollowLinks = false; } |
81f25632 | 164 | |
844f90fb VZ |
165 | // from a directory name, file base name and extension |
166 | wxFileName(const wxString& path, | |
167 | const wxString& name, | |
168 | const wxString& ext, | |
169 | wxPathFormat format = wxPATH_NATIVE) | |
c063adeb | 170 | { Assign(path, name, ext, format); m_dontFollowLinks = false; } |
844f90fb | 171 | |
844f90fb VZ |
172 | // the same for delayed initialization |
173 | ||
844f90fb | 174 | void Assign(const wxFileName& filepath); |
04c943b1 | 175 | |
844f90fb VZ |
176 | void Assign(const wxString& fullpath, |
177 | wxPathFormat format = wxPATH_NATIVE); | |
04c943b1 VZ |
178 | |
179 | void Assign(const wxString& volume, | |
180 | const wxString& path, | |
181 | const wxString& name, | |
182 | const wxString& ext, | |
dfecbee5 | 183 | bool hasExt, |
04c943b1 VZ |
184 | wxPathFormat format = wxPATH_NATIVE); |
185 | ||
dfecbee5 VZ |
186 | void Assign(const wxString& volume, |
187 | const wxString& path, | |
188 | const wxString& name, | |
189 | const wxString& ext, | |
190 | wxPathFormat format = wxPATH_NATIVE) | |
191 | { Assign(volume, path, name, ext, !ext.empty(), format); } | |
192 | ||
844f90fb VZ |
193 | void Assign(const wxString& path, |
194 | const wxString& name, | |
195 | wxPathFormat format = wxPATH_NATIVE); | |
04c943b1 | 196 | |
844f90fb VZ |
197 | void Assign(const wxString& path, |
198 | const wxString& name, | |
199 | const wxString& ext, | |
4c2deb19 | 200 | wxPathFormat format = wxPATH_NATIVE); |
04c943b1 | 201 | |
52dbd056 | 202 | void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE); |
844f90fb | 203 | |
788722ac JS |
204 | // assorted assignment operators |
205 | ||
206 | wxFileName& operator=(const wxFileName& filename) | |
a09307ab | 207 | { if (this != &filename) Assign(filename); return *this; } |
788722ac JS |
208 | |
209 | wxFileName& operator=(const wxString& filename) | |
210 | { Assign(filename); return *this; } | |
211 | ||
844f90fb VZ |
212 | // reset all components to default, uninitialized state |
213 | void Clear(); | |
214 | ||
215 | // static pseudo constructors | |
520200fd VZ |
216 | static wxFileName FileName(const wxString& file, |
217 | wxPathFormat format = wxPATH_NATIVE); | |
218 | static wxFileName DirName(const wxString& dir, | |
219 | wxPathFormat format = wxPATH_NATIVE); | |
844f90fb | 220 | |
951cd180 | 221 | // file tests |
844f90fb VZ |
222 | |
223 | // is the filename valid at all? | |
a96b8d39 | 224 | bool IsOk() const |
a62848fd | 225 | { |
a96b8d39 | 226 | // we're fine if we have the path or the name or if we're a root dir |
27b2dd53 | 227 | return m_dirs.size() != 0 || !m_name.empty() || !m_relative || |
dfecbee5 | 228 | !m_ext.empty() || m_hasExt; |
a96b8d39 | 229 | } |
844f90fb | 230 | |
996d3fe3 | 231 | // does the file with this name exist? |
8e41796c | 232 | bool FileExists() const; |
a35b27b1 | 233 | static bool FileExists( const wxString &file ); |
097ead30 | 234 | |
996d3fe3 | 235 | // does the directory with this name exist? |
8e41796c | 236 | bool DirExists() const; |
a35b27b1 | 237 | static bool DirExists( const wxString &dir ); |
097ead30 | 238 | |
996d3fe3 VZ |
239 | // does anything at all with this name (i.e. file, directory or some |
240 | // other file system object such as a device, socket, ...) exist? | |
c50db847 VZ |
241 | bool Exists(int flags = wxFILE_EXISTS_ANY) const; |
242 | static bool Exists(const wxString& path, int flags = wxFILE_EXISTS_ANY); | |
996d3fe3 VZ |
243 | |
244 | ||
3ff07edb RR |
245 | // checks on most common flags for files/directories; |
246 | // more platform-specific features (like e.g. Unix permissions) are not | |
247 | // available in wxFileName | |
248 | ||
249 | bool IsDirWritable() const { return wxIsWritable(GetPath()); } | |
250 | static bool IsDirWritable(const wxString &path) { return wxDirExists(path) && wxIsWritable(path); } | |
251 | ||
252 | bool IsDirReadable() const { return wxIsReadable(GetPath()); } | |
253 | static bool IsDirReadable(const wxString &path) { return wxDirExists(path) && wxIsReadable(path); } | |
254 | ||
255 | // NOTE: IsDirExecutable() is not present because the meaning of "executable" | |
256 | // directory is very platform-dependent and also not so useful | |
257 | ||
258 | bool IsFileWritable() const { return wxIsWritable(GetFullPath()); } | |
259 | static bool IsFileWritable(const wxString &path) { return wxFileExists(path) && wxIsWritable(path); } | |
260 | ||
261 | bool IsFileReadable() const { return wxIsReadable(GetFullPath()); } | |
262 | static bool IsFileReadable(const wxString &path) { return wxFileExists(path) && wxIsReadable(path); } | |
263 | ||
264 | bool IsFileExecutable() const { return wxIsExecutable(GetFullPath()); } | |
265 | static bool IsFileExecutable(const wxString &path) { return wxFileExists(path) && wxIsExecutable(path); } | |
266 | ||
844f90fb | 267 | |
951cd180 | 268 | // time functions |
e2b87f38 | 269 | #if wxUSE_DATETIME |
6dbb903b | 270 | // set the file last access/mod and creation times |
951cd180 | 271 | // (any of the pointers may be NULL) |
6dbb903b VZ |
272 | bool SetTimes(const wxDateTime *dtAccess, |
273 | const wxDateTime *dtMod, | |
d9e80dce | 274 | const wxDateTime *dtCreate) const; |
951cd180 VZ |
275 | |
276 | // set the access and modification times to the current moment | |
d9e80dce | 277 | bool Touch() const; |
951cd180 | 278 | |
6dbb903b | 279 | // return the last access, last modification and create times |
951cd180 VZ |
280 | // (any of the pointers may be NULL) |
281 | bool GetTimes(wxDateTime *dtAccess, | |
282 | wxDateTime *dtMod, | |
6dbb903b | 283 | wxDateTime *dtCreate) const; |
951cd180 VZ |
284 | |
285 | // convenience wrapper: get just the last mod time of the file | |
286 | wxDateTime GetModificationTime() const | |
287 | { | |
288 | wxDateTime dtMod; | |
289 | (void)GetTimes(NULL, &dtMod, NULL); | |
290 | return dtMod; | |
291 | } | |
e2b87f38 | 292 | #endif // wxUSE_DATETIME |
951cd180 | 293 | |
ac9e3f1f | 294 | #if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON |
4dfbcdd5 | 295 | bool MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) ; |
d9e80dce | 296 | bool MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) const; |
4dfbcdd5 SC |
297 | // gets the 'common' type and creator for a certain extension |
298 | static bool MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator ) ; | |
299 | // registers application defined extensions and their default type and creator | |
300 | static void MacRegisterDefaultTypeAndCreator( const wxString& ext , wxUint32 type , wxUint32 creator ) ; | |
301 | // looks up the appropriate type and creator from the registration and then sets | |
302 | bool MacSetDefaultTypeAndCreator() ; | |
303 | #endif | |
fb969475 | 304 | |
844f90fb VZ |
305 | // various file/dir operations |
306 | ||
307 | // retrieve the value of the current working directory | |
6f91bc33 VZ |
308 | void AssignCwd(const wxString& volume = wxEmptyString); |
309 | static wxString GetCwd(const wxString& volume = wxEmptyString); | |
097ead30 | 310 | |
844f90fb | 311 | // change the current working directory |
d9e80dce | 312 | bool SetCwd() const; |
a35b27b1 | 313 | static bool SetCwd( const wxString &cwd ); |
097ead30 | 314 | |
844f90fb | 315 | // get the value of user home (Unix only mainly) |
a35b27b1 RR |
316 | void AssignHomeDir(); |
317 | static wxString GetHomeDir(); | |
097ead30 | 318 | |
8d7d6dea JS |
319 | // get the system temporary directory |
320 | static wxString GetTempDir(); | |
321 | ||
b70a2866 MW |
322 | #if wxUSE_FILE || wxUSE_FFILE |
323 | // get a temp file name starting with the specified prefix | |
324 | void AssignTempFileName(const wxString& prefix); | |
325 | static wxString CreateTempFileName(const wxString& prefix); | |
326 | #endif // wxUSE_FILE | |
327 | ||
68351053 | 328 | #if wxUSE_FILE |
df22f860 VZ |
329 | // get a temp file name starting with the specified prefix and open the |
330 | // file passed to us using this name for writing (atomically if | |
331 | // possible) | |
b70a2866 | 332 | void AssignTempFileName(const wxString& prefix, wxFile *fileTemp); |
df22f860 | 333 | static wxString CreateTempFileName(const wxString& prefix, |
b70a2866 | 334 | wxFile *fileTemp); |
68351053 | 335 | #endif // wxUSE_FILE |
097ead30 | 336 | |
b70a2866 MW |
337 | #if wxUSE_FFILE |
338 | // get a temp file name starting with the specified prefix and open the | |
339 | // file passed to us using this name for writing (atomically if | |
340 | // possible) | |
341 | void AssignTempFileName(const wxString& prefix, wxFFile *fileTemp); | |
342 | static wxString CreateTempFileName(const wxString& prefix, | |
343 | wxFFile *fileTemp); | |
344 | #endif // wxUSE_FFILE | |
345 | ||
f0ce3409 | 346 | // directory creation and removal. |
89391a4e | 347 | bool Mkdir(int perm = wxS_DIR_DEFAULT, int flags = 0) const; |
110c5094 VZ |
348 | static bool Mkdir(const wxString &dir, int perm = wxS_DIR_DEFAULT, |
349 | int flags = 0); | |
097ead30 | 350 | |
89391a4e | 351 | bool Rmdir(int flags = 0) const; |
110c5094 | 352 | static bool Rmdir(const wxString &dir, int flags = 0); |
097ead30 | 353 | |
844f90fb VZ |
354 | // operations on the path |
355 | ||
356 | // normalize the path: with the default flags value, the path will be | |
357 | // made absolute, without any ".." and "." and all environment | |
358 | // variables will be expanded in it | |
359 | // | |
360 | // this may be done using another (than current) value of cwd | |
32a0d013 | 361 | bool Normalize(int flags = wxPATH_NORM_ALL, |
844f90fb VZ |
362 | const wxString& cwd = wxEmptyString, |
363 | wxPathFormat format = wxPATH_NATIVE); | |
097ead30 | 364 | |
f7d886af VZ |
365 | // get a path path relative to the given base directory, i.e. opposite |
366 | // of Normalize | |
367 | // | |
368 | // pass an empty string to get a path relative to the working directory | |
369 | // | |
f363e05c | 370 | // returns true if the file name was modified, false if we failed to do |
f7d886af VZ |
371 | // anything with it (happens when the file is on a different volume, |
372 | // for example) | |
fda7962d | 373 | bool MakeRelativeTo(const wxString& pathBase = wxEmptyString, |
f7d886af VZ |
374 | wxPathFormat format = wxPATH_NATIVE); |
375 | ||
0894707e VS |
376 | // make the path absolute |
377 | // | |
378 | // this may be done using another (than current) value of cwd | |
379 | bool MakeAbsolute(const wxString& cwd = wxEmptyString, | |
380 | wxPathFormat format = wxPATH_NATIVE) | |
381 | { return Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE | | |
382 | wxPATH_NORM_TILDE, cwd, format); } | |
f7d886af | 383 | |
c063adeb VZ |
384 | |
385 | // If the path is a symbolic link (Unix-only), indicate that all | |
386 | // filesystem operations on this path should be performed on the link | |
387 | // itself and not on the file it points to, as is the case by default. | |
388 | // | |
389 | // No effect if this is not a symbolic link. | |
390 | void DontFollowLink() | |
391 | { | |
392 | m_dontFollowLinks = true; | |
393 | } | |
394 | ||
395 | // If the path is a symbolic link (Unix-only), returns whether various | |
396 | // file operations should act on the link itself, or on its target. | |
397 | // | |
398 | // This does not test if the path is really a symlink or not. | |
399 | bool ShouldFollowLink() const | |
400 | { | |
401 | return !m_dontFollowLinks; | |
402 | } | |
403 | ||
ff95fdbb | 404 | #if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE |
21f60945 JS |
405 | // if the path is a shortcut, return the target and optionally, |
406 | // the arguments | |
ff95fdbb VS |
407 | bool GetShortcutTarget(const wxString& shortcutPath, |
408 | wxString& targetFilename, | |
d9e80dce | 409 | wxString* arguments = NULL) const; |
21f60945 JS |
410 | #endif |
411 | ||
395f3aa8 FM |
412 | #ifndef __WXWINCE__ |
413 | // if the path contains the value of the environment variable named envname | |
414 | // then this function replaces it with the string obtained from | |
415 | // wxString::Format(replacementFmtString, value_of_envname_variable) | |
416 | // | |
417 | // Example: | |
418 | // wxFileName fn("/usr/openwin/lib/someFile"); | |
419 | // fn.ReplaceEnvVariable("OPENWINHOME"); | |
420 | // // now fn.GetFullPath() == "$OPENWINHOME/lib/someFile" | |
421 | bool ReplaceEnvVariable(const wxString& envname, | |
422 | const wxString& replacementFmtString = "$%s", | |
423 | wxPathFormat format = wxPATH_NATIVE); | |
424 | #endif | |
425 | ||
426 | // replaces, if present in the path, the home directory for the given user | |
427 | // (see wxGetHomeDir) with a tilde | |
428 | bool ReplaceHomeDir(wxPathFormat format = wxPATH_NATIVE); | |
429 | ||
430 | ||
df5ddbca | 431 | // Comparison |
844f90fb | 432 | |
2b5f62a0 VZ |
433 | // compares with the rules of the given platforms format |
434 | bool SameAs(const wxFileName& filepath, | |
435 | wxPathFormat format = wxPATH_NATIVE) const; | |
436 | ||
437 | // compare with another filename object | |
438 | bool operator==(const wxFileName& filename) const | |
439 | { return SameAs(filename); } | |
440 | bool operator!=(const wxFileName& filename) const | |
441 | { return !SameAs(filename); } | |
442 | ||
443 | // compare with a filename string interpreted as a native file name | |
444 | bool operator==(const wxString& filename) const | |
445 | { return SameAs(wxFileName(filename)); } | |
446 | bool operator!=(const wxString& filename) const | |
447 | { return !SameAs(wxFileName(filename)); } | |
844f90fb | 448 | |
04c943b1 | 449 | // are the file names of this type cases sensitive? |
844f90fb | 450 | static bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE ); |
04c943b1 VZ |
451 | |
452 | // is this filename absolute? | |
6d3d1c2e | 453 | bool IsAbsolute(wxPathFormat format = wxPATH_NATIVE) const; |
844f90fb | 454 | |
04c943b1 | 455 | // is this filename relative? |
6d3d1c2e VZ |
456 | bool IsRelative(wxPathFormat format = wxPATH_NATIVE) const |
457 | { return !IsAbsolute(format); } | |
04c943b1 | 458 | |
f363e05c VZ |
459 | // Returns the characters that aren't allowed in filenames |
460 | // on the specified platform. | |
461 | static wxString GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE); | |
462 | ||
04c943b1 VZ |
463 | // Information about path format |
464 | ||
6d3d1c2e VZ |
465 | // get the string separating the volume from the path for this format, |
466 | // return an empty string if this format doesn't support the notion of | |
467 | // volumes at all | |
04c943b1 VZ |
468 | static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE); |
469 | ||
844f90fb VZ |
470 | // get the string of path separators for this format |
471 | static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE); | |
472 | ||
f1e77933 VZ |
473 | // get the string of path terminators, i.e. characters which terminate the |
474 | // path | |
475 | static wxString GetPathTerminators(wxPathFormat format = wxPATH_NATIVE); | |
476 | ||
6d3d1c2e | 477 | // get the canonical path separator for this format |
c9f78968 | 478 | static wxUniChar GetPathSeparator(wxPathFormat format = wxPATH_NATIVE) |
6d3d1c2e VZ |
479 | { return GetPathSeparators(format)[0u]; } |
480 | ||
844f90fb VZ |
481 | // is the char a path separator for this format? |
482 | static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE); | |
483 | ||
e01a788e VZ |
484 | // is this is a DOS path which beings with a windows unique volume name |
485 | // ('\\?\Volume{guid}\')? | |
486 | static bool IsMSWUniqueVolumeNamePath(const wxString& path, | |
487 | wxPathFormat format = wxPATH_NATIVE); | |
488 | ||
df5ddbca | 489 | // Dir accessors |
df5168c4 | 490 | size_t GetDirCount() const { return m_dirs.size(); } |
2458d90b VZ |
491 | void AppendDir(const wxString& dir); |
492 | void PrependDir(const wxString& dir); | |
493 | void InsertDir(size_t before, const wxString& dir); | |
494 | void RemoveDir(size_t pos); | |
495 | void RemoveLastDir() { RemoveDir(GetDirCount() - 1); } | |
097ead30 | 496 | |
df5ddbca | 497 | // Other accessors |
0b40f3d8 RR |
498 | void SetExt( const wxString &ext ) { m_ext = ext; m_hasExt = !m_ext.empty(); } |
499 | void ClearExt() { m_ext = wxEmptyString; m_hasExt = false; } | |
500 | void SetEmptyExt() { m_ext = wxT(""); m_hasExt = true; } | |
df5ddbca | 501 | wxString GetExt() const { return m_ext; } |
4d4edca3 | 502 | bool HasExt() const { return m_hasExt; } |
097ead30 | 503 | |
df5ddbca RR |
504 | void SetName( const wxString &name ) { m_name = name; } |
505 | wxString GetName() const { return m_name; } | |
04c943b1 VZ |
506 | bool HasName() const { return !m_name.empty(); } |
507 | ||
508 | void SetVolume( const wxString &volume ) { m_volume = volume; } | |
509 | wxString GetVolume() const { return m_volume; } | |
510 | bool HasVolume() const { return !m_volume.empty(); } | |
097ead30 | 511 | |
7124df9b VZ |
512 | // full name is the file name + extension (but without the path) |
513 | void SetFullName(const wxString& fullname); | |
844f90fb | 514 | wxString GetFullName() const; |
097ead30 | 515 | |
04c943b1 | 516 | const wxArrayString& GetDirs() const { return m_dirs; } |
097ead30 | 517 | |
33b97389 | 518 | // flags are combination of wxPATH_GET_XXX flags |
93fa67c0 VZ |
519 | wxString GetPath(int flags = wxPATH_GET_VOLUME, |
520 | wxPathFormat format = wxPATH_NATIVE) const; | |
33b97389 | 521 | |
a7b51bc8 RR |
522 | // Replace current path with this one |
523 | void SetPath( const wxString &path, wxPathFormat format = wxPATH_NATIVE ); | |
097ead30 | 524 | |
df5ddbca RR |
525 | // Construct full path with name and ext |
526 | wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const; | |
097ead30 | 527 | |
9e9b65c1 JS |
528 | // Return the short form of the path (returns identity on non-Windows platforms) |
529 | wxString GetShortPath() const; | |
530 | ||
531 | // Return the long form of the path (returns identity on non-Windows platforms) | |
532 | wxString GetLongPath() const; | |
533 | ||
2db991f4 VZ |
534 | // Is this a file or directory (not necessarily an existing one) |
535 | bool IsDir() const { return m_name.empty() && m_ext.empty(); } | |
536 | ||
9e8d8607 VZ |
537 | // various helpers |
538 | ||
539 | // get the canonical path format for this platform | |
df5ddbca | 540 | static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE ); |
097ead30 | 541 | |
04c943b1 VZ |
542 | // split a fullpath into the volume, path, (base) name and extension |
543 | // (all of the pointers can be NULL) | |
9e8d8607 | 544 | static void SplitPath(const wxString& fullpath, |
04c943b1 | 545 | wxString *volume, |
9e8d8607 VZ |
546 | wxString *path, |
547 | wxString *name, | |
548 | wxString *ext, | |
dfecbee5 | 549 | bool *hasExt = NULL, |
9e8d8607 VZ |
550 | wxPathFormat format = wxPATH_NATIVE); |
551 | ||
dfecbee5 VZ |
552 | static void SplitPath(const wxString& fullpath, |
553 | wxString *volume, | |
554 | wxString *path, | |
555 | wxString *name, | |
556 | wxString *ext, | |
1a6255e6 | 557 | wxPathFormat format) |
dfecbee5 VZ |
558 | { |
559 | SplitPath(fullpath, volume, path, name, ext, NULL, format); | |
560 | } | |
561 | ||
562 | // compatibility version: volume is part of path | |
04c943b1 VZ |
563 | static void SplitPath(const wxString& fullpath, |
564 | wxString *path, | |
565 | wxString *name, | |
566 | wxString *ext, | |
6f91bc33 | 567 | wxPathFormat format = wxPATH_NATIVE); |
04c943b1 | 568 | |
f1e77933 VZ |
569 | // split a path into volume and pure path part |
570 | static void SplitVolume(const wxString& fullpathWithVolume, | |
571 | wxString *volume, | |
572 | wxString *path, | |
573 | wxPathFormat format = wxPATH_NATIVE); | |
33b97389 | 574 | |
e06e8119 | 575 | // strip the file extension: "foo.bar" => "foo" (but ".baz" => ".baz") |
181dd701 VZ |
576 | static wxString StripExtension(const wxString& fullpath); |
577 | ||
35c2aa4f VZ |
578 | #ifdef wxHAS_FILESYSTEM_VOLUMES |
579 | // return the string representing a file system volume, or drive | |
580 | static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR); | |
581 | #endif // wxHAS_FILESYSTEM_VOLUMES | |
582 | ||
583 | // File size | |
98080d5c | 584 | |
bd08f2f7 | 585 | #if wxUSE_LONGLONG |
98080d5c JS |
586 | // returns the size of the given filename |
587 | wxULongLong GetSize() const; | |
588 | static wxULongLong GetSize(const wxString &file); | |
589 | ||
590 | // returns the size in a human readable form | |
b2edb8f3 VZ |
591 | wxString |
592 | GetHumanReadableSize(const wxString& nullsize = _("Not available"), | |
593 | int precision = 1, | |
2febffba | 594 | wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL) const; |
b2edb8f3 VZ |
595 | static wxString |
596 | GetHumanReadableSize(const wxULongLong& sz, | |
597 | const wxString& nullsize = _("Not available"), | |
598 | int precision = 1, | |
2febffba | 599 | wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL); |
bd08f2f7 | 600 | #endif // wxUSE_LONGLONG |
98080d5c JS |
601 | |
602 | ||
33b97389 VZ |
603 | // deprecated methods, don't use any more |
604 | // -------------------------------------- | |
605 | ||
4ce1efe1 | 606 | #ifndef __DIGITALMARS__ |
33b97389 VZ |
607 | wxString GetPath( bool withSep, wxPathFormat format = wxPATH_NATIVE ) const |
608 | { return GetPath(withSep ? wxPATH_GET_SEPARATOR : 0, format); } | |
4ce1efe1 | 609 | #endif |
33b97389 | 610 | wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const |
ab9a58f4 | 611 | { return GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format); } |
33b97389 | 612 | |
df5ddbca | 613 | private: |
5bb9aeb2 VZ |
614 | // check whether this dir is valid for Append/Prepend/InsertDir() |
615 | static bool IsValidDirComponent(const wxString& dir); | |
616 | ||
04c943b1 VZ |
617 | // the drive/volume/device specification (always empty for Unix) |
618 | wxString m_volume; | |
619 | ||
844f90fb | 620 | // the path components of the file |
df5ddbca | 621 | wxArrayString m_dirs; |
844f90fb VZ |
622 | |
623 | // the file name and extension (empty for directories) | |
624 | wxString m_name, | |
625 | m_ext; | |
6d3d1c2e VZ |
626 | |
627 | // when m_dirs is empty it may mean either that we have no path at all or | |
628 | // that our path is '/', i.e. the root directory | |
629 | // | |
630 | // we use m_relative to distinguish between these two cases, it will be | |
f363e05c | 631 | // true in the former and false in the latter |
6d3d1c2e | 632 | // |
f363e05c | 633 | // NB: the path is not absolute just because m_relative is false, it still |
6d3d1c2e | 634 | // needs the drive (i.e. volume) in some formats (Windows) |
353f41cb | 635 | bool m_relative; |
dfecbee5 VZ |
636 | |
637 | // when m_ext is empty, it may be because we don't have any extension or | |
638 | // because we have an empty extension | |
639 | // | |
640 | // the difference is important as file with name "foo" and without | |
641 | // extension has full name "foo" while with empty extension it is "foo." | |
642 | bool m_hasExt; | |
c063adeb VZ |
643 | |
644 | // by default, symlinks are dereferenced but this flag can be set with | |
645 | // DontFollowLink() to change this and make different operations work on | |
646 | // this file path itself instead of the target of the symlink | |
647 | bool m_dontFollowLinks; | |
df5ddbca RR |
648 | }; |
649 | ||
097ead30 | 650 | #endif // _WX_FILENAME_H_ |
df5ddbca | 651 |