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