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