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