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