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