]>
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" |
df5ddbca | 31 | |
68351053 | 32 | #if wxUSE_FILE |
b5dbe15d | 33 | class WXDLLIMPEXP_FWD_BASE wxFile; |
68351053 | 34 | #endif |
df22f860 | 35 | |
b70a2866 | 36 | #if wxUSE_FFILE |
b5dbe15d | 37 | class WXDLLIMPEXP_FWD_BASE wxFFile; |
b70a2866 MW |
38 | #endif |
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 |
47 | enum wxPathFormat |
48 | { | |
844f90fb | 49 | wxPATH_NATIVE = 0, // the path format for the current platform |
097ead30 | 50 | wxPATH_UNIX, |
f363e05c | 51 | wxPATH_BEOS = wxPATH_UNIX, |
097ead30 VZ |
52 | wxPATH_MAC, |
53 | wxPATH_DOS, | |
f363e05c VZ |
54 | wxPATH_WIN = wxPATH_DOS, |
55 | wxPATH_OS2 = wxPATH_DOS, | |
3c621059 | 56 | wxPATH_VMS, |
ee66f092 | 57 | |
f363e05c | 58 | wxPATH_MAX // Not a valid value for specifying path format |
097ead30 | 59 | }; |
ee66f092 | 60 | |
097ead30 VZ |
61 | // the kind of normalization to do with the file name: these values can be |
62 | // or'd together to perform several operations at once | |
63 | enum wxPathNormalize | |
64 | { | |
65 | wxPATH_NORM_ENV_VARS = 0x0001, // replace env vars with their values | |
844f90fb | 66 | wxPATH_NORM_DOTS = 0x0002, // squeeze all .. and . and prepend cwd |
097ead30 | 67 | wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user |
844f90fb VZ |
68 | wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower |
69 | wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute | |
9e9b65c1 | 70 | wxPATH_NORM_LONG = 0x0020, // make the path the long form |
21f60945 JS |
71 | wxPATH_NORM_SHORTCUT = 0x0040, // resolve the shortcut, if it is a shortcut |
72 | wxPATH_NORM_ALL = 0x00ff & ~wxPATH_NORM_CASE | |
df5ddbca RR |
73 | }; |
74 | ||
33b97389 VZ |
75 | // what exactly should GetPath() return? |
76 | enum | |
77 | { | |
78 | wxPATH_GET_VOLUME = 0x0001, // include the volume if applicable | |
79 | wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator | |
80 | }; | |
81 | ||
1527281e VZ |
82 | // MkDir flags |
83 | enum | |
84 | { | |
85 | wxPATH_MKDIR_FULL = 0x0001 // create directories recursively | |
86 | }; | |
87 | ||
bd08f2f7 | 88 | #if wxUSE_LONGLONG |
98080d5c | 89 | // error code of wxFileName::GetSize() |
060668a1 | 90 | extern WXDLLIMPEXP_DATA_BASE(const wxULongLong) wxInvalidSize; |
bd08f2f7 | 91 | #endif // wxUSE_LONGLONG |
98080d5c JS |
92 | |
93 | ||
3ff07edb | 94 | |
097ead30 VZ |
95 | // ---------------------------------------------------------------------------- |
96 | // wxFileName: encapsulates a file path | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
bddd7a8d | 99 | class WXDLLIMPEXP_BASE wxFileName |
df5ddbca RR |
100 | { |
101 | public: | |
102 | // constructors and assignment | |
844f90fb VZ |
103 | |
104 | // the usual stuff | |
fb969475 | 105 | wxFileName() { Clear(); } |
520200fd | 106 | wxFileName(const wxFileName& filepath) { Assign(filepath); } |
844f90fb VZ |
107 | |
108 | // from a full filename: if it terminates with a '/', a directory path | |
109 | // is contructed (the name will be empty), otherwise a file name and | |
110 | // extension are extracted from it | |
111 | wxFileName( const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE ) | |
112 | { Assign( fullpath, format ); } | |
113 | ||
114 | // from a directory name and a file name | |
115 | wxFileName(const wxString& path, | |
116 | const wxString& name, | |
117 | wxPathFormat format = wxPATH_NATIVE) | |
118 | { Assign(path, name, format); } | |
119 | ||
81f25632 VZ |
120 | // from a volume, directory name, file base name and extension |
121 | wxFileName(const wxString& volume, | |
122 | const wxString& path, | |
123 | const wxString& name, | |
124 | const wxString& ext, | |
125 | wxPathFormat format = wxPATH_NATIVE) | |
126 | { Assign(volume, path, name, ext, format); } | |
127 | ||
844f90fb VZ |
128 | // from a directory name, file base name and extension |
129 | wxFileName(const wxString& path, | |
130 | const wxString& name, | |
131 | const wxString& ext, | |
132 | wxPathFormat format = wxPATH_NATIVE) | |
133 | { Assign(path, name, ext, format); } | |
134 | ||
844f90fb VZ |
135 | // the same for delayed initialization |
136 | ||
844f90fb | 137 | void Assign(const wxFileName& filepath); |
04c943b1 | 138 | |
844f90fb VZ |
139 | void Assign(const wxString& fullpath, |
140 | wxPathFormat format = wxPATH_NATIVE); | |
04c943b1 VZ |
141 | |
142 | void Assign(const wxString& volume, | |
143 | const wxString& path, | |
144 | const wxString& name, | |
145 | const wxString& ext, | |
dfecbee5 | 146 | bool hasExt, |
04c943b1 VZ |
147 | wxPathFormat format = wxPATH_NATIVE); |
148 | ||
dfecbee5 VZ |
149 | void Assign(const wxString& volume, |
150 | const wxString& path, | |
151 | const wxString& name, | |
152 | const wxString& ext, | |
153 | wxPathFormat format = wxPATH_NATIVE) | |
154 | { Assign(volume, path, name, ext, !ext.empty(), format); } | |
155 | ||
844f90fb VZ |
156 | void Assign(const wxString& path, |
157 | const wxString& name, | |
158 | wxPathFormat format = wxPATH_NATIVE); | |
04c943b1 | 159 | |
844f90fb VZ |
160 | void Assign(const wxString& path, |
161 | const wxString& name, | |
162 | const wxString& ext, | |
4c2deb19 | 163 | wxPathFormat format = wxPATH_NATIVE); |
04c943b1 | 164 | |
52dbd056 | 165 | void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE); |
844f90fb | 166 | |
788722ac JS |
167 | // assorted assignment operators |
168 | ||
169 | wxFileName& operator=(const wxFileName& filename) | |
170 | { Assign(filename); return *this; } | |
171 | ||
172 | wxFileName& operator=(const wxString& filename) | |
173 | { Assign(filename); return *this; } | |
174 | ||
844f90fb VZ |
175 | // reset all components to default, uninitialized state |
176 | void Clear(); | |
177 | ||
178 | // static pseudo constructors | |
520200fd VZ |
179 | static wxFileName FileName(const wxString& file, |
180 | wxPathFormat format = wxPATH_NATIVE); | |
181 | static wxFileName DirName(const wxString& dir, | |
182 | wxPathFormat format = wxPATH_NATIVE); | |
844f90fb | 183 | |
951cd180 | 184 | // file tests |
844f90fb VZ |
185 | |
186 | // is the filename valid at all? | |
a96b8d39 | 187 | bool IsOk() const |
a62848fd | 188 | { |
a96b8d39 | 189 | // we're fine if we have the path or the name or if we're a root dir |
27b2dd53 | 190 | return m_dirs.size() != 0 || !m_name.empty() || !m_relative || |
dfecbee5 | 191 | !m_ext.empty() || m_hasExt; |
a96b8d39 | 192 | } |
844f90fb VZ |
193 | |
194 | // does the file with this name exists? | |
8e41796c | 195 | bool FileExists() const; |
a35b27b1 | 196 | static bool FileExists( const wxString &file ); |
097ead30 | 197 | |
844f90fb | 198 | // does the directory with this name exists? |
8e41796c | 199 | bool DirExists() const; |
a35b27b1 | 200 | static bool DirExists( const wxString &dir ); |
097ead30 | 201 | |
3ff07edb RR |
202 | // checks on most common flags for files/directories; |
203 | // more platform-specific features (like e.g. Unix permissions) are not | |
204 | // available in wxFileName | |
205 | ||
206 | bool IsDirWritable() const { return wxIsWritable(GetPath()); } | |
207 | static bool IsDirWritable(const wxString &path) { return wxDirExists(path) && wxIsWritable(path); } | |
208 | ||
209 | bool IsDirReadable() const { return wxIsReadable(GetPath()); } | |
210 | static bool IsDirReadable(const wxString &path) { return wxDirExists(path) && wxIsReadable(path); } | |
211 | ||
212 | // NOTE: IsDirExecutable() is not present because the meaning of "executable" | |
213 | // directory is very platform-dependent and also not so useful | |
214 | ||
215 | bool IsFileWritable() const { return wxIsWritable(GetFullPath()); } | |
216 | static bool IsFileWritable(const wxString &path) { return wxFileExists(path) && wxIsWritable(path); } | |
217 | ||
218 | bool IsFileReadable() const { return wxIsReadable(GetFullPath()); } | |
219 | static bool IsFileReadable(const wxString &path) { return wxFileExists(path) && wxIsReadable(path); } | |
220 | ||
221 | bool IsFileExecutable() const { return wxIsExecutable(GetFullPath()); } | |
222 | static bool IsFileExecutable(const wxString &path) { return wxFileExists(path) && wxIsExecutable(path); } | |
223 | ||
844f90fb | 224 | |
951cd180 | 225 | // time functions |
e2b87f38 | 226 | #if wxUSE_DATETIME |
6dbb903b | 227 | // set the file last access/mod and creation times |
951cd180 | 228 | // (any of the pointers may be NULL) |
6dbb903b VZ |
229 | bool SetTimes(const wxDateTime *dtAccess, |
230 | const wxDateTime *dtMod, | |
231 | const wxDateTime *dtCreate); | |
951cd180 VZ |
232 | |
233 | // set the access and modification times to the current moment | |
234 | bool Touch(); | |
235 | ||
6dbb903b | 236 | // return the last access, last modification and create times |
951cd180 VZ |
237 | // (any of the pointers may be NULL) |
238 | bool GetTimes(wxDateTime *dtAccess, | |
239 | wxDateTime *dtMod, | |
6dbb903b | 240 | wxDateTime *dtCreate) const; |
951cd180 VZ |
241 | |
242 | // convenience wrapper: get just the last mod time of the file | |
243 | wxDateTime GetModificationTime() const | |
244 | { | |
245 | wxDateTime dtMod; | |
246 | (void)GetTimes(NULL, &dtMod, NULL); | |
247 | return dtMod; | |
248 | } | |
e2b87f38 | 249 | #endif // wxUSE_DATETIME |
951cd180 | 250 | |
ac9e3f1f | 251 | #if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON |
4dfbcdd5 SC |
252 | bool MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) ; |
253 | bool MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) ; | |
254 | // gets the 'common' type and creator for a certain extension | |
255 | static bool MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator ) ; | |
256 | // registers application defined extensions and their default type and creator | |
257 | static void MacRegisterDefaultTypeAndCreator( const wxString& ext , wxUint32 type , wxUint32 creator ) ; | |
258 | // looks up the appropriate type and creator from the registration and then sets | |
259 | bool MacSetDefaultTypeAndCreator() ; | |
260 | #endif | |
fb969475 | 261 | |
844f90fb VZ |
262 | // various file/dir operations |
263 | ||
264 | // retrieve the value of the current working directory | |
6f91bc33 VZ |
265 | void AssignCwd(const wxString& volume = wxEmptyString); |
266 | static wxString GetCwd(const wxString& volume = wxEmptyString); | |
097ead30 | 267 | |
844f90fb | 268 | // change the current working directory |
a35b27b1 RR |
269 | bool SetCwd(); |
270 | static bool SetCwd( const wxString &cwd ); | |
097ead30 | 271 | |
844f90fb | 272 | // get the value of user home (Unix only mainly) |
a35b27b1 RR |
273 | void AssignHomeDir(); |
274 | static wxString GetHomeDir(); | |
097ead30 | 275 | |
8d7d6dea JS |
276 | // get the system temporary directory |
277 | static wxString GetTempDir(); | |
278 | ||
b70a2866 MW |
279 | #if wxUSE_FILE || wxUSE_FFILE |
280 | // get a temp file name starting with the specified prefix | |
281 | void AssignTempFileName(const wxString& prefix); | |
282 | static wxString CreateTempFileName(const wxString& prefix); | |
283 | #endif // wxUSE_FILE | |
284 | ||
68351053 | 285 | #if wxUSE_FILE |
df22f860 VZ |
286 | // get a temp file name starting with the specified prefix and open the |
287 | // file passed to us using this name for writing (atomically if | |
288 | // possible) | |
b70a2866 | 289 | void AssignTempFileName(const wxString& prefix, wxFile *fileTemp); |
df22f860 | 290 | static wxString CreateTempFileName(const wxString& prefix, |
b70a2866 | 291 | wxFile *fileTemp); |
68351053 | 292 | #endif // wxUSE_FILE |
097ead30 | 293 | |
b70a2866 MW |
294 | #if wxUSE_FFILE |
295 | // get a temp file name starting with the specified prefix and open the | |
296 | // file passed to us using this name for writing (atomically if | |
297 | // possible) | |
298 | void AssignTempFileName(const wxString& prefix, wxFFile *fileTemp); | |
299 | static wxString CreateTempFileName(const wxString& prefix, | |
300 | wxFFile *fileTemp); | |
301 | #endif // wxUSE_FFILE | |
302 | ||
f0ce3409 | 303 | // directory creation and removal. |
1527281e VZ |
304 | bool Mkdir( int perm = 0777, int flags = 0); |
305 | static bool Mkdir( const wxString &dir, int perm = 0777, int flags = 0 ); | |
097ead30 | 306 | |
a35b27b1 RR |
307 | bool Rmdir(); |
308 | static bool Rmdir( const wxString &dir ); | |
097ead30 | 309 | |
844f90fb VZ |
310 | // operations on the path |
311 | ||
312 | // normalize the path: with the default flags value, the path will be | |
313 | // made absolute, without any ".." and "." and all environment | |
314 | // variables will be expanded in it | |
315 | // | |
316 | // this may be done using another (than current) value of cwd | |
32a0d013 | 317 | bool Normalize(int flags = wxPATH_NORM_ALL, |
844f90fb VZ |
318 | const wxString& cwd = wxEmptyString, |
319 | wxPathFormat format = wxPATH_NATIVE); | |
097ead30 | 320 | |
f7d886af VZ |
321 | // get a path path relative to the given base directory, i.e. opposite |
322 | // of Normalize | |
323 | // | |
324 | // pass an empty string to get a path relative to the working directory | |
325 | // | |
f363e05c | 326 | // returns true if the file name was modified, false if we failed to do |
f7d886af VZ |
327 | // anything with it (happens when the file is on a different volume, |
328 | // for example) | |
fda7962d | 329 | bool MakeRelativeTo(const wxString& pathBase = wxEmptyString, |
f7d886af VZ |
330 | wxPathFormat format = wxPATH_NATIVE); |
331 | ||
0894707e VS |
332 | // make the path absolute |
333 | // | |
334 | // this may be done using another (than current) value of cwd | |
335 | bool MakeAbsolute(const wxString& cwd = wxEmptyString, | |
336 | wxPathFormat format = wxPATH_NATIVE) | |
337 | { return Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE | | |
338 | wxPATH_NORM_TILDE, cwd, format); } | |
f7d886af | 339 | |
ff95fdbb | 340 | #if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE |
21f60945 JS |
341 | // if the path is a shortcut, return the target and optionally, |
342 | // the arguments | |
ff95fdbb VS |
343 | bool GetShortcutTarget(const wxString& shortcutPath, |
344 | wxString& targetFilename, | |
345 | wxString* arguments = NULL); | |
21f60945 JS |
346 | #endif |
347 | ||
df5ddbca | 348 | // Comparison |
844f90fb | 349 | |
2b5f62a0 VZ |
350 | // compares with the rules of the given platforms format |
351 | bool SameAs(const wxFileName& filepath, | |
352 | wxPathFormat format = wxPATH_NATIVE) const; | |
353 | ||
354 | // compare with another filename object | |
355 | bool operator==(const wxFileName& filename) const | |
356 | { return SameAs(filename); } | |
357 | bool operator!=(const wxFileName& filename) const | |
358 | { return !SameAs(filename); } | |
359 | ||
360 | // compare with a filename string interpreted as a native file name | |
361 | bool operator==(const wxString& filename) const | |
362 | { return SameAs(wxFileName(filename)); } | |
363 | bool operator!=(const wxString& filename) const | |
364 | { return !SameAs(wxFileName(filename)); } | |
844f90fb | 365 | |
04c943b1 | 366 | // are the file names of this type cases sensitive? |
844f90fb | 367 | static bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE ); |
04c943b1 VZ |
368 | |
369 | // is this filename absolute? | |
6d3d1c2e | 370 | bool IsAbsolute(wxPathFormat format = wxPATH_NATIVE) const; |
844f90fb | 371 | |
04c943b1 | 372 | // is this filename relative? |
6d3d1c2e VZ |
373 | bool IsRelative(wxPathFormat format = wxPATH_NATIVE) const |
374 | { return !IsAbsolute(format); } | |
04c943b1 | 375 | |
f363e05c VZ |
376 | // Returns the characters that aren't allowed in filenames |
377 | // on the specified platform. | |
378 | static wxString GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE); | |
379 | ||
04c943b1 VZ |
380 | // Information about path format |
381 | ||
6d3d1c2e VZ |
382 | // get the string separating the volume from the path for this format, |
383 | // return an empty string if this format doesn't support the notion of | |
384 | // volumes at all | |
04c943b1 VZ |
385 | static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE); |
386 | ||
844f90fb VZ |
387 | // get the string of path separators for this format |
388 | static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE); | |
389 | ||
f1e77933 VZ |
390 | // get the string of path terminators, i.e. characters which terminate the |
391 | // path | |
392 | static wxString GetPathTerminators(wxPathFormat format = wxPATH_NATIVE); | |
393 | ||
6d3d1c2e | 394 | // get the canonical path separator for this format |
c9f78968 | 395 | static wxUniChar GetPathSeparator(wxPathFormat format = wxPATH_NATIVE) |
6d3d1c2e VZ |
396 | { return GetPathSeparators(format)[0u]; } |
397 | ||
844f90fb VZ |
398 | // is the char a path separator for this format? |
399 | static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE); | |
400 | ||
df5ddbca | 401 | // Dir accessors |
df5168c4 | 402 | size_t GetDirCount() const { return m_dirs.size(); } |
2458d90b VZ |
403 | void AppendDir(const wxString& dir); |
404 | void PrependDir(const wxString& dir); | |
405 | void InsertDir(size_t before, const wxString& dir); | |
406 | void RemoveDir(size_t pos); | |
407 | void RemoveLastDir() { RemoveDir(GetDirCount() - 1); } | |
097ead30 | 408 | |
df5ddbca | 409 | // Other accessors |
0b40f3d8 RR |
410 | void SetExt( const wxString &ext ) { m_ext = ext; m_hasExt = !m_ext.empty(); } |
411 | void ClearExt() { m_ext = wxEmptyString; m_hasExt = false; } | |
412 | void SetEmptyExt() { m_ext = wxT(""); m_hasExt = true; } | |
df5ddbca | 413 | wxString GetExt() const { return m_ext; } |
4d4edca3 | 414 | bool HasExt() const { return m_hasExt; } |
097ead30 | 415 | |
df5ddbca RR |
416 | void SetName( const wxString &name ) { m_name = name; } |
417 | wxString GetName() const { return m_name; } | |
04c943b1 VZ |
418 | bool HasName() const { return !m_name.empty(); } |
419 | ||
420 | void SetVolume( const wxString &volume ) { m_volume = volume; } | |
421 | wxString GetVolume() const { return m_volume; } | |
422 | bool HasVolume() const { return !m_volume.empty(); } | |
097ead30 | 423 | |
7124df9b VZ |
424 | // full name is the file name + extension (but without the path) |
425 | void SetFullName(const wxString& fullname); | |
844f90fb | 426 | wxString GetFullName() const; |
097ead30 | 427 | |
04c943b1 | 428 | const wxArrayString& GetDirs() const { return m_dirs; } |
097ead30 | 429 | |
33b97389 | 430 | // flags are combination of wxPATH_GET_XXX flags |
93fa67c0 VZ |
431 | wxString GetPath(int flags = wxPATH_GET_VOLUME, |
432 | wxPathFormat format = wxPATH_NATIVE) const; | |
33b97389 | 433 | |
a7b51bc8 RR |
434 | // Replace current path with this one |
435 | void SetPath( const wxString &path, wxPathFormat format = wxPATH_NATIVE ); | |
097ead30 | 436 | |
df5ddbca RR |
437 | // Construct full path with name and ext |
438 | wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const; | |
097ead30 | 439 | |
9e9b65c1 JS |
440 | // Return the short form of the path (returns identity on non-Windows platforms) |
441 | wxString GetShortPath() const; | |
442 | ||
443 | // Return the long form of the path (returns identity on non-Windows platforms) | |
444 | wxString GetLongPath() const; | |
445 | ||
2db991f4 VZ |
446 | // Is this a file or directory (not necessarily an existing one) |
447 | bool IsDir() const { return m_name.empty() && m_ext.empty(); } | |
448 | ||
9e8d8607 VZ |
449 | // various helpers |
450 | ||
451 | // get the canonical path format for this platform | |
df5ddbca | 452 | static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE ); |
097ead30 | 453 | |
04c943b1 VZ |
454 | // split a fullpath into the volume, path, (base) name and extension |
455 | // (all of the pointers can be NULL) | |
9e8d8607 | 456 | static void SplitPath(const wxString& fullpath, |
04c943b1 | 457 | wxString *volume, |
9e8d8607 VZ |
458 | wxString *path, |
459 | wxString *name, | |
460 | wxString *ext, | |
dfecbee5 | 461 | bool *hasExt = NULL, |
9e8d8607 VZ |
462 | wxPathFormat format = wxPATH_NATIVE); |
463 | ||
dfecbee5 VZ |
464 | static void SplitPath(const wxString& fullpath, |
465 | wxString *volume, | |
466 | wxString *path, | |
467 | wxString *name, | |
468 | wxString *ext, | |
1a6255e6 | 469 | wxPathFormat format) |
dfecbee5 VZ |
470 | { |
471 | SplitPath(fullpath, volume, path, name, ext, NULL, format); | |
472 | } | |
473 | ||
474 | // compatibility version: volume is part of path | |
04c943b1 VZ |
475 | static void SplitPath(const wxString& fullpath, |
476 | wxString *path, | |
477 | wxString *name, | |
478 | wxString *ext, | |
6f91bc33 | 479 | wxPathFormat format = wxPATH_NATIVE); |
04c943b1 | 480 | |
f1e77933 VZ |
481 | // split a path into volume and pure path part |
482 | static void SplitVolume(const wxString& fullpathWithVolume, | |
483 | wxString *volume, | |
484 | wxString *path, | |
485 | wxPathFormat format = wxPATH_NATIVE); | |
33b97389 | 486 | |
98080d5c JS |
487 | // Filesize |
488 | ||
bd08f2f7 | 489 | #if wxUSE_LONGLONG |
98080d5c JS |
490 | // returns the size of the given filename |
491 | wxULongLong GetSize() const; | |
492 | static wxULongLong GetSize(const wxString &file); | |
493 | ||
494 | // returns the size in a human readable form | |
64fb0e20 | 495 | wxString GetHumanReadableSize(const wxString &nullsize = wxGetTranslation(_T("Not available")), |
98080d5c JS |
496 | int precision = 1) const; |
497 | static wxString GetHumanReadableSize(const wxULongLong &sz, | |
64fb0e20 | 498 | const wxString &nullsize = wxGetTranslation(_T("Not available")), |
98080d5c | 499 | int precision = 1); |
bd08f2f7 | 500 | #endif // wxUSE_LONGLONG |
98080d5c JS |
501 | |
502 | ||
33b97389 VZ |
503 | // deprecated methods, don't use any more |
504 | // -------------------------------------- | |
505 | ||
4ce1efe1 | 506 | #ifndef __DIGITALMARS__ |
33b97389 VZ |
507 | wxString GetPath( bool withSep, wxPathFormat format = wxPATH_NATIVE ) const |
508 | { return GetPath(withSep ? wxPATH_GET_SEPARATOR : 0, format); } | |
4ce1efe1 | 509 | #endif |
33b97389 | 510 | wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const |
ab9a58f4 | 511 | { return GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format); } |
33b97389 | 512 | |
df5ddbca | 513 | private: |
5bb9aeb2 VZ |
514 | // check whether this dir is valid for Append/Prepend/InsertDir() |
515 | static bool IsValidDirComponent(const wxString& dir); | |
516 | ||
04c943b1 VZ |
517 | // the drive/volume/device specification (always empty for Unix) |
518 | wxString m_volume; | |
519 | ||
844f90fb | 520 | // the path components of the file |
df5ddbca | 521 | wxArrayString m_dirs; |
844f90fb VZ |
522 | |
523 | // the file name and extension (empty for directories) | |
524 | wxString m_name, | |
525 | m_ext; | |
6d3d1c2e VZ |
526 | |
527 | // when m_dirs is empty it may mean either that we have no path at all or | |
528 | // that our path is '/', i.e. the root directory | |
529 | // | |
530 | // we use m_relative to distinguish between these two cases, it will be | |
f363e05c | 531 | // true in the former and false in the latter |
6d3d1c2e | 532 | // |
f363e05c | 533 | // NB: the path is not absolute just because m_relative is false, it still |
6d3d1c2e | 534 | // needs the drive (i.e. volume) in some formats (Windows) |
353f41cb | 535 | bool m_relative; |
dfecbee5 VZ |
536 | |
537 | // when m_ext is empty, it may be because we don't have any extension or | |
538 | // because we have an empty extension | |
539 | // | |
540 | // the difference is important as file with name "foo" and without | |
541 | // extension has full name "foo" while with empty extension it is "foo." | |
542 | bool m_hasExt; | |
df5ddbca RR |
543 | }; |
544 | ||
097ead30 | 545 | #endif // _WX_FILENAME_H_ |
df5ddbca | 546 |