Coverage Report

Created: 2026-03-07 06:57

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