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