]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/filename.h
Fix FILETIME <-> wxDateTime conversions while DST is in effect in wxMSW.
[wxWidgets.git] / interface / wx / filename.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: filename.h
e54c96f1 3// Purpose: interface of wxFileName
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
0b70c946 9
eadd3970
FM
10/**
11 The various values for the path format: this mainly affects the path
0b70c946
FM
12 separator but also whether or not the path has the drive part
13 (as under Windows).
14
15 See wxFileName for more info.
16*/
17enum wxPathFormat
18{
19 wxPATH_NATIVE = 0, //!< the path format for the current platform.
20 wxPATH_UNIX,
21 wxPATH_BEOS = wxPATH_UNIX,
22 wxPATH_MAC,
23 wxPATH_DOS,
24 wxPATH_WIN = wxPATH_DOS,
25 wxPATH_OS2 = wxPATH_DOS,
26 wxPATH_VMS,
27
28 wxPATH_MAX //!< Not a valid value for specifying path format
29};
30
b2edb8f3
VZ
31/**
32 Different conventions for human readable sizes.
33
34 @see wxFileName::GetHumanReadableSize().
35
36 @since 2.9.1
37*/
38enum wxSizeConvention
39{
72822505
VZ
40 /// 1024 bytes = 1KB.
41 wxSIZE_CONV_TRADITIONAL,
42
43 /// 1024 bytes = 1KiB.
2febffba 44 wxSIZE_CONV_IEC,
b2edb8f3
VZ
45
46 /// 1000 bytes = 1KB.
72822505 47 wxSIZE_CONV_SI
b2edb8f3
VZ
48};
49
0b70c946 50
eadd3970
FM
51/**
52 The kind of normalization to do with the file name: these values can be
0b70c946
FM
53 or'd together to perform several operations at once.
54 See wxFileName::Normalize() for more info.
55*/
56enum wxPathNormalize
57{
395f3aa8
FM
58 //! Replace environment variables with their values.
59 //! wxFileName understands both Unix and Windows (but only under Windows) environment
60 //! variables expansion: i.e. @c "$var", @c "$(var)" and @c "${var}" are always understood
61 //! and in addition under Windows @c "%var%" is also.
62 wxPATH_NORM_ENV_VARS = 0x0001,
63
31eacdaf 64 wxPATH_NORM_DOTS = 0x0002, //!< Squeeze all @c ".." and @c ".".
eadd3970
FM
65 wxPATH_NORM_TILDE = 0x0004, //!< Replace @c "~" and @c "~user" (Unix only).
66 wxPATH_NORM_CASE = 0x0008, //!< If the platform is case insensitive, make lowercase the path.
67 wxPATH_NORM_ABSOLUTE = 0x0010, //!< Make the path absolute.
68 wxPATH_NORM_LONG = 0x0020, //!< Expand the path to the "long" form (Windows only).
69 wxPATH_NORM_SHORTCUT = 0x0040, //!< Resolve the shortcut, if it is a shortcut (Windows only).
70
71 //! A value indicating all normalization flags except for @c wxPATH_NORM_CASE.
0b70c946
FM
72 wxPATH_NORM_ALL = 0x00ff & ~wxPATH_NORM_CASE
73};
74
110c5094
VZ
75/**
76 Flags for wxFileName::Rmdir().
77 */
78enum
79{
80 /// Delete the specified directory and its subdirectories if they are empty.
81 wxPATH_RMDIR_FULL = 1,
82
83 /**
84 Delete the specified directory and all the files and subdirectories in it
85 recursively.
86
87 This flag is obviously @b dangerous and should be used with care and
88 after asking the user for confirmation.
89 */
90 wxPATH_RMDIR_RECURSIVE = 2
91};
92
c50db847
VZ
93/**
94 Flags for wxFileName::Exists().
95
96 @since 2.9.5
97 */
98enum
99{
100 wxFILE_EXISTS_REGULAR = 0x0001, //!< Check for existence of a regular file
101 wxFILE_EXISTS_DIR = 0x0002, //!< Check for existence of a directory
0f57172b
VZ
102 /**
103 Check for existence of a symlink.
104
58263bb4
VZ
105 Notice that this flag also sets ::wxFILE_EXISTS_NO_FOLLOW, otherwise it
106 would never be satisfied as wxFileName::Exists() would be checking for
107 the existence of the symlink target and not the symlink itself.
0f57172b 108 */
58263bb4 109 wxFILE_EXISTS_SYMLINK = 0x1004,
c50db847
VZ
110 wxFILE_EXISTS_DEVICE = 0x0008, //!< Check for existence of a device
111 wxFILE_EXISTS_FIFO = 0x0016, //!< Check for existence of a FIFO
112 wxFILE_EXISTS_SOCKET = 0x0032, //!< Check for existence of a socket
c50db847 113 wxFILE_EXISTS_NO_FOLLOW = 0x1000 //!< Don't dereference a contained symbolic link
58263bb4 114 wxFILE_EXISTS_ANY = 0x1FFF, //!< Check for existence of anything
c50db847
VZ
115};
116
0b70c946
FM
117/**
118 The return value of wxFileName::GetSize() in case of error.
119*/
120wxULongLong wxInvalidSize;
121
122
23324ae1
FM
123/**
124 @class wxFileName
7c913512 125
76e9224e
FM
126 wxFileName encapsulates a file name.
127
128 This class serves two purposes: first, it provides the functions to split the
129 file names into components and to recombine these components in the full file
130 name which can then be passed to the OS file functions
131 (and @ref group_funcmacro_file "wxWidgets functions" wrapping them).
23324ae1
FM
132 Second, it includes the functions for working with the files itself. Note that
133 to change the file data you should use wxFile class instead.
134 wxFileName provides functions for working with the file attributes.
7c913512 135
23324ae1
FM
136 When working with directory names (i.e. without filename and extension)
137 make sure not to misuse the file name part of this class with the last
138 directory. Instead initialize the wxFileName instance like this:
7c913512 139
23324ae1
FM
140 @code
141 wxFileName dirname( "C:\mydir", "" );
142 MyMethod( dirname.GetPath() );
143 @endcode
7c913512 144
0b70c946 145 The same can be done using the static method wxFileName::DirName():
7c913512 146
23324ae1
FM
147 @code
148 wxFileName dirname = wxFileName::DirName( "C:\mydir" );
149 MyMethod( dirname.GetPath() );
150 @endcode
7c913512 151
0b70c946
FM
152 Accordingly, methods dealing with directories or directory names like
153 wxFileName::IsDirReadable() use wxFileName::GetPath() whereas methods dealing
154 with file names like wxFileName::IsFileReadable() use wxFileName::GetFullPath().
7c913512 155
d13b34d3 156 If it is not known whether a string contains a directory name or a complete
0b70c946
FM
157 file name (such as when interpreting user input) you need to use the static
158 function wxFileName::DirExists() (or its identical variants wxDir::Exists() and
159 wxDirExists()) and construct the wxFileName instance accordingly.
160 This will only work if the directory actually exists, of course:
7c913512 161
23324ae1
FM
162 @code
163 wxString user_input;
164 // get input from user
7c913512 165
23324ae1
FM
166 wxFileName fname;
167 if (wxDirExists(user_input))
168 fname.AssignDir( user_input );
169 else
170 fname.Assign( user_input );
171 @endcode
7c913512 172
0b70c946
FM
173 Please note that many wxFileName methods accept the path format argument
174 which is by @c wxPATH_NATIVE by default meaning to use the path format
175 native for the current platform.
176 The path format affects the operation of wxFileName functions in several ways:
177 first and foremost, it defines the path separator character to use, but it
178 also affects other things such as whether the path has the drive part or not.
179 See wxPathFormat for more info.
180
181
182 @section filename_format File name format
183
184 wxFileName currently supports the file names in the Unix, DOS/Windows,
185 Mac OS and VMS formats. Although these formats are quite different,
186 wxFileName tries to treat them all in the same generic way.
187 It supposes that all file names consist of the following parts: the volume
188 (also known as drive under Windows or device under VMS), the path which is
189 a sequence of directory names separated by the path separators and the full
190 filename itself which, in turn, is composed from the base file name and the
191 extension. All of the individual components of the file name may be empty
192 and, for example, the volume name is always empty under Unix, but if they
193 are all empty simultaneously, the filename object is considered to be in an
194 invalid state and wxFileName::IsOk() returns false for it.
195
196 File names can be case-sensitive or not, the function wxFileName::IsCaseSensitive()
197 allows to determine this. The rules for determining whether the file name is
198 absolute or relative also depend on the file name format and the only portable way
199 to answer this question is to use wxFileName::IsAbsolute() or wxFileName::IsRelative()
200 method.
201
202 Note that on Windows,"X:" refers to the current working directory on drive X.
203 Therefore, a wxFileName instance constructed from for example "X:dir/file.ext"
204 treats the portion beyond drive separator as being relative to that directory.
205 To ensure that the filename is absolute, you may use wxFileName::MakeAbsolute().
206 There is also an inverse function wxFileName::MakeRelativeTo() which undoes
207 what wxFileName::Normalize(wxPATH_NORM_DOTS) does.
208 Other functions returning information about the file format provided by this
209 class are wxFileName::GetVolumeSeparator(), wxFileName::IsPathSeparator().
210
211
212 @section filename_construction File name construction
213
214 You can initialize a wxFileName instance using one of the following functions:
215
216 @li wxFileName::wxFileName()
217 @li wxFileName::Assign()
218 @li wxFileName::AssignCwd()
219 @li wxFileName::AssignDir()
220 @li wxFileName::AssignHomeDir()
f95032ca 221 @li wxFileName::AssignTempFileName()
0b70c946
FM
222 @li wxFileName::DirName()
223 @li wxFileName::FileName()
224 @li wxFileName::operator=()
225
226
227 @section filename_tests File name tests
228
229 Before doing other tests, you should use wxFileName::IsOk() to verify that
230 the filename is well defined. If it is, FileExists() can be used to test whether
231 a file with such name exists and wxFileName::DirExists() can be used to test
232 for directory existence.
233 File names should be compared using the wxFileName::SameAs() method or
234 wxFileName::operator==(). For testing basic access modes, you can use:
235
236 @li wxFileName::IsDirWritable()
237 @li wxFileName::IsDirReadable()
238 @li wxFileName::IsFileWritable()
239 @li wxFileName::IsFileReadable()
240 @li wxFileName::IsFileExecutable()
241
242
243 @section filename_components File name components
244
245 These functions allow to examine and modify the individual directories
246 of the path:
247
248 @li wxFileName::AppendDir()
249 @li wxFileName::InsertDir()
250 @li wxFileName::GetDirCount()
251 @li wxFileName::PrependDir()
252 @li wxFileName::RemoveDir()
253 @li wxFileName::RemoveLastDir()
254
255 To change the components of the file name individually you can use the
256 following functions:
257
258 @li wxFileName::GetExt()
259 @li wxFileName::GetName()
260 @li wxFileName::GetVolume()
261 @li wxFileName::HasExt()
262 @li wxFileName::HasName()
263 @li wxFileName::HasVolume()
264 @li wxFileName::SetExt()
265 @li wxFileName::ClearExt()
266 @li wxFileName::SetEmptyExt()
267 @li wxFileName::SetName()
268 @li wxFileName::SetVolume()
269
270 You can initialize a wxFileName instance using one of the following functions:
271
272
273 @section filename_operations File name operations
274
275 These methods allow to work with the file creation, access and modification
276 times. Note that not all filesystems under all platforms implement these times
277 in the same way. For example, the access time under Windows has a resolution of
278 one day (so it is really the access date and not time). The access time may be
279 updated when the file is executed or not depending on the platform.
280
281 @li wxFileName::GetModificationTime()
282 @li wxFileName::GetTimes()
283 @li wxFileName::SetTimes()
284 @li wxFileName::Touch()
285
286 Other file system operations functions are:
287
288 @li wxFileName::Mkdir()
289 @li wxFileName::Rmdir()
ca4bcd88
RR
290
291
23324ae1
FM
292 @library{wxbase}
293 @category{file}
23324ae1 294*/
7c913512 295class wxFileName
23324ae1
FM
296{
297public:
23324ae1 298 /**
ca4bcd88 299 Default constructor.
23324ae1
FM
300 */
301 wxFileName();
0b70c946 302
ca4bcd88
RR
303 /**
304 Copy constructor.
305 */
7c913512 306 wxFileName(const wxFileName& filename);
0b70c946 307
ca4bcd88 308 /**
0b70c946
FM
309 Constructor taking a full filename.
310
311 If it terminates with a '/', a directory path is constructed
312 (the name will be empty), otherwise a file name and extension
313 are extracted from it.
ca4bcd88 314 */
7c913512
FM
315 wxFileName(const wxString& fullpath,
316 wxPathFormat format = wxPATH_NATIVE);
0b70c946 317
ca4bcd88
RR
318 /**
319 Constructor a directory name and file name.
320 */
7c913512
FM
321 wxFileName(const wxString& path, const wxString& name,
322 wxPathFormat format = wxPATH_NATIVE);
0b70c946 323
ca4bcd88
RR
324 /**
325 Constructor from a directory name, base file name and extension.
326 */
7c913512
FM
327 wxFileName(const wxString& path, const wxString& name,
328 const wxString& ext,
329 wxPathFormat format = wxPATH_NATIVE);
0b70c946 330
ca4bcd88
RR
331 /**
332 Constructor from a volume name, a directory name, base file name and extension.
333 */
7c913512
FM
334 wxFileName(const wxString& volume, const wxString& path,
335 const wxString& name,
336 const wxString& ext,
337 wxPathFormat format = wxPATH_NATIVE);
23324ae1
FM
338
339 /**
6aa4e398
VZ
340 Appends a directory component to the path.
341
342 This component should contain a single directory name level, i.e. not
343 contain any path or volume separators nor should it be empty, otherwise
344 the function does nothing and returns false (and generates an assert
345 failure in debug build).
346
347 Notice that the return value is only available in wxWidgets 2.9.5 or
348 later.
23324ae1 349 */
6aa4e398 350 bool AppendDir(const wxString& dir);
23324ae1 351
23324ae1 352 /**
ca4bcd88 353 Creates the file name from another filename object.
23324ae1
FM
354 */
355 void Assign(const wxFileName& filepath);
0b70c946 356
ca4bcd88
RR
357 /**
358 Creates the file name from a full file name with a path.
359 */
7c913512
FM
360 void Assign(const wxString& fullpath,
361 wxPathFormat format = wxPATH_NATIVE);
0b70c946 362
ca4bcd88 363 /**
d13b34d3 364 Creates the file name from volume, path, name and extension.
ca4bcd88 365 */
7c913512
FM
366 void Assign(const wxString& volume, const wxString& path,
367 const wxString& name,
368 const wxString& ext,
369 bool hasExt,
370 wxPathFormat format = wxPATH_NATIVE);
0b70c946 371
ca4bcd88 372 /**
d13b34d3 373 Creates the file name from volume, path, name and extension.
ca4bcd88 374 */
7c913512
FM
375 void Assign(const wxString& volume, const wxString& path,
376 const wxString& name,
377 const wxString& ext,
378 wxPathFormat format = wxPATH_NATIVE);
0b70c946 379
ca4bcd88
RR
380 /**
381 Creates the file name from file path and file name.
382 */
7c913512
FM
383 void Assign(const wxString& path, const wxString& name,
384 wxPathFormat format = wxPATH_NATIVE);
0b70c946 385
ca4bcd88
RR
386 /**
387 Creates the file name from path, name and extension.
388 */
7c913512
FM
389 void Assign(const wxString& path, const wxString& name,
390 const wxString& ext,
391 wxPathFormat format = wxPATH_NATIVE);
23324ae1
FM
392
393 /**
394 Makes this object refer to the current working directory on the specified
4cc4bfaf 395 volume (or current volume if @a volume is empty).
3c4f71cc 396
4cc4bfaf 397 @see GetCwd()
23324ae1 398 */
382f12e4 399 void AssignCwd(const wxString& volume = wxEmptyString);
23324ae1
FM
400
401 /**
0b70c946
FM
402 Sets this file name object to the given directory name.
403 The name and extension will be empty.
23324ae1
FM
404 */
405 void AssignDir(const wxString& dir,
406 wxPathFormat format = wxPATH_NATIVE);
407
408 /**
409 Sets this file name object to the home directory.
410 */
411 void AssignHomeDir();
412
413 /**
0b70c946
FM
414 The function calls CreateTempFileName() to create a temporary file
415 and sets this object to the name of the file.
a44f3b5a 416
0b70c946 417 If a temporary file couldn't be created, the object is put into
f95032ca
RR
418 an invalid state (see IsOk()).
419 */
420 void AssignTempFileName(const wxString& prefix);
421
422 /**
423 The function calls CreateTempFileName() to create a temporary
424 file name and open @a fileTemp with it.
425
426 If the file couldn't be opened, the object is put into
427 an invalid state (see IsOk()).
23324ae1 428 */
a44f3b5a 429 void AssignTempFileName(const wxString& prefix, wxFile* fileTemp);
f95032ca
RR
430
431 /**
432 The function calls CreateTempFileName() to create a temporary
433 file name and open @a fileTemp with it.
434
435 If the file couldn't be opened, the object is put into
436 an invalid state (see IsOk()).
437 */
a44f3b5a 438 void AssignTempFileName(const wxString& prefix, wxFFile* fileTemp);
23324ae1
FM
439
440 /**
441 Reset all components to default, uninitialized state.
442 */
443 void Clear();
444
445 /**
7c913512 446 Removes the extension from the file name resulting in a
23324ae1 447 file name with no trailing dot.
3c4f71cc 448
4cc4bfaf 449 @see SetExt(), SetEmptyExt()
23324ae1 450 */
2bd56258 451 void ClearExt();
23324ae1 452
7740f1c7 453
23324ae1 454 /**
0b70c946 455 Returns a temporary file name starting with the given @e prefix.
7740f1c7
VZ
456 If @a prefix is an absolute path and ends in a separator, the
457 temporary file is created in this directory; if it is an absolute
458 filepath or there is no separator, the temporary file is created in its
459 path, with the 'name' segment prepended to the temporary filename;
460 otherwise it is created in the default system directory for temporary
461 files or in the current directory.
0b70c946
FM
462
463 If the function succeeds, the temporary file is actually created.
7740f1c7
VZ
464 If @a fileTemp is not @NULL, this wxFile will be opened using the name of
465 the temporary file. Where possible this is done in an atomic way to ensure that
466 no race condition occurs between creating the temporary file name and opening
467 it, which might lead to a security compromise on multiuser systems.
468 If @a fileTemp is @NULL, the file is created but not opened.
23324ae1 469 Under Unix, the temporary file will have read and write permissions for the
7740f1c7 470 owner only, to minimize security problems.
3c4f71cc 471
7c913512 472 @param prefix
7740f1c7
VZ
473 Location to use for the temporary file name construction. If @a prefix
474 is a directory it must have a terminal separator
7c913512 475 @param fileTemp
7740f1c7 476 The file to open, or @NULL just to get the name
3c4f71cc 477
7740f1c7 478 @return The full temporary filepath, or an empty string on error.
23324ae1
FM
479 */
480 static wxString CreateTempFileName(const wxString& prefix,
4cc4bfaf 481 wxFile* fileTemp = NULL);
7740f1c7
VZ
482
483 /**
484 This is the same as CreateTempFileName(const wxString &prefix, wxFile *fileTemp)
485 but takes a wxFFile parameter instead of wxFile.
486 */
882678eb
FM
487 static wxString CreateTempFileName(const wxString& prefix,
488 wxFFile* fileTemp = NULL);
7740f1c7 489
23324ae1 490
23324ae1
FM
491 /**
492 Returns @true if the directory with this name exists.
996d3fe3
VZ
493
494 Notice that this function tests the directory part of this object,
495 i.e. the string returned by GetPath(), and not the full path returned
496 by GetFullPath().
497
498 @see FileExists(), Exists()
23324ae1 499 */
0b70c946
FM
500 bool DirExists() const;
501
ca4bcd88 502 /**
d38315df 503 Returns @true if the directory with name @a dir exists.
996d3fe3
VZ
504
505 @see FileExists(), Exists()
ca4bcd88 506 */
0b70c946 507 static bool DirExists(const wxString& dir);
23324ae1
FM
508
509 /**
510 Returns the object corresponding to the directory with the given name.
4cc4bfaf 511 The @a dir parameter may have trailing path separator or not.
23324ae1
FM
512 */
513 static wxFileName DirName(const wxString& dir,
514 wxPathFormat format = wxPATH_NATIVE);
515
996d3fe3 516 /**
c063adeb
VZ
517 Turns off symlink dereferencing.
518
519 By default, all operations in this class work on the target of a
520 symbolic link (symlink) if the path of the file is actually a symlink.
521 Using this method allows to turn off this "symlink following" behaviour
522 and apply the operations to this path itself, even if it is a symlink.
523
524 The following methods are currently affected by this option:
525 - GetTimes() (but not SetTimes() as there is no portable way to
526 change the time of symlink itself).
527 - Existence checks: FileExists(), DirExists() and Exists() (notice
528 that static versions of these methods always follow symlinks).
529 - IsSameAs().
530
531 @see ShouldFollowLink()
532
533 @since 2.9.5
534 */
535 void DontFollowLink();
536
537 /**
996d3fe3
VZ
538 Calls the static overload of this function with the full path of this
539 object.
540
c50db847 541 @since 2.9.4 (@a flags is new since 2.9.5)
996d3fe3 542 */
c50db847 543 bool Exists(int flags = wxFILE_EXISTS_ANY) const;
996d3fe3
VZ
544
545 /**
546 Returns @true if either a file or a directory or something else with
547 this name exists in the file system.
548
c50db847
VZ
549 Don't dereference @a path if it is a symbolic link and @a flags
550 argument contains ::wxFILE_EXISTS_NO_FOLLOW.
551
996d3fe3 552 This method is equivalent to @code FileExists() || DirExists() @endcode
c50db847 553 under Windows, but under Unix it also returns true if the file
996d3fe3
VZ
554 identifies a special file system object such as a device, a socket or a
555 FIFO.
556
c50db847
VZ
557 Alternatively you may check for the existence of a file system entry of
558 a specific type by passing the appropriate @a flags (this parameter is
559 new since wxWidgets 2.9.5). E.g. to test for a symbolic link existence
560 you could use ::wxFILE_EXISTS_SYMLINK.
561
996d3fe3
VZ
562 @since 2.9.4
563
564 @see FileExists(), DirExists()
565 */
c50db847 566 static bool Exists(const wxString& path, int flags = wxFILE_EXISTS_ANY);
996d3fe3 567
23324ae1 568 /**
ca4bcd88 569 Returns @true if the file with this name exists.
3c4f71cc 570
996d3fe3 571 @see DirExists(), Exists()
23324ae1 572 */
0b70c946
FM
573 bool FileExists() const;
574
23324ae1 575 /**
d38315df 576 Returns @true if the file with name @a file exists.
3c4f71cc 577
996d3fe3 578 @see DirExists(), Exists()
23324ae1 579 */
0b70c946 580 static bool FileExists(const wxString& file);
23324ae1
FM
581
582 /**
583 Returns the file name object corresponding to the given @e file. This
584 function exists mainly for symmetry with DirName().
585 */
586 static wxFileName FileName(const wxString& file,
587 wxPathFormat format = wxPATH_NATIVE);
588
589 /**
0b70c946
FM
590 Retrieves the value of the current working directory on the specified volume.
591 If the volume is empty, the program's current working directory is returned for
592 the current volume.
3c4f71cc 593
d29a9a8a 594 @return The string containing the current working directory or an empty
0b70c946 595 string on error.
3c4f71cc 596
4cc4bfaf 597 @see AssignCwd()
23324ae1 598 */
0b70c946 599 static wxString GetCwd(const wxString& volume = wxEmptyString);
23324ae1
FM
600
601 /**
602 Returns the number of directories in the file name.
603 */
328f5751 604 size_t GetDirCount() const;
23324ae1
FM
605
606 /**
607 Returns the directories in string array form.
608 */
0b70c946 609 const wxArrayString& GetDirs() const;
23324ae1
FM
610
611 /**
612 Returns the file name extension.
613 */
328f5751 614 wxString GetExt() const;
23324ae1
FM
615
616 /**
0b70c946
FM
617 Returns the characters that can't be used in filenames and directory names
618 for the specified format.
23324ae1
FM
619 */
620 static wxString GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE);
621
622 /**
623 Returns the canonical path format for this platform.
624 */
625 static wxPathFormat GetFormat(wxPathFormat format = wxPATH_NATIVE);
626
627 /**
628 Returns the full name (including extension but excluding directories).
629 */
328f5751 630 wxString GetFullName() const;
23324ae1
FM
631
632 /**
633 Returns the full path with name and extension.
634 */
328f5751 635 wxString GetFullPath(wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
636
637 /**
638 Returns the home directory.
639 */
640 static wxString GetHomeDir();
641
b2edb8f3 642 //@{
23324ae1 643 /**
b2edb8f3
VZ
644 Returns the representation of the file size in a human-readable form.
645
646 In the first version, the size of this file is used. In the second one,
647 the specified size @a bytes is used.
648
649 If the file size could not be retrieved or @a bytes is ::wxInvalidSize
650 or zero, the @c failmsg string is returned.
651
652 Otherwise the returned string is a floating-point number with @c
653 precision decimal digits followed by the abbreviation of the unit used.
654 By default the traditional, although incorrect, convention of using SI
655 units for multiples of 1024 is used, i.e. returned string will use
656 suffixes of B, KB, MB, GB, TB for bytes, kilobytes, megabytes,
657 gigabytes and terabytes respectively. With the IEC convention the names
e02edc0e 658 of the units are changed to B, KiB, MiB, GiB and TiB for bytes,
d13b34d3 659 kibibytes, mebibytes, gibibytes and tebibytes. Finally, with SI
b2edb8f3
VZ
660 convention the same B, KB, MB, GB and TB suffixes are used but in their
661 correct SI meaning, i.e. as multiples of 1000 and not 1024.
662
663 Support for the different size conventions is new in wxWidgets 2.9.1,
664 in previous versions only the traditional convention was implemented.
665 */
666 wxString
667 GetHumanReadableSize(const wxString& failmsg = _("Not available"),
668 int precision = 1,
2febffba 669 wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL) const;
b2edb8f3
VZ
670
671 static wxString
672 GetHumanReadableSize(const wxULongLong& bytes,
673 const wxString& nullsize = _("Not available"),
674 int precision = 1,
2febffba 675 wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL);
b2edb8f3 676 //@}
23324ae1
FM
677
678 /**
0b70c946 679 Return the long form of the path (returns identity on non-Windows platforms).
23324ae1 680 */
328f5751 681 wxString GetLongPath() const;
23324ae1
FM
682
683 /**
684 Returns the last time the file was last modified.
685 */
328f5751 686 wxDateTime GetModificationTime() const;
23324ae1
FM
687
688 /**
689 Returns the name part of the filename (without extension).
3c4f71cc 690
4cc4bfaf 691 @see GetFullName()
23324ae1 692 */
328f5751 693 wxString GetName() const;
23324ae1
FM
694
695 /**
35c2aa4f
VZ
696 Returns the path part of the filename (without the name or extension).
697
698 The possible flags values are:
3c4f71cc 699
eadd3970 700 - @b wxPATH_GET_VOLUME:
35c2aa4f
VZ
701 Return the path with the volume (does nothing for the filename formats
702 without volumes), otherwise the path without volume part is returned.
3c4f71cc 703
0b70c946 704 - @b wxPATH_GET_SEPARATOR:
35c2aa4f
VZ
705 Return the path with the trailing separator, if this flag is not given
706 there will be no separator at the end of the path.
707
0b70c946 708 - @b wxPATH_NO_SEPARATOR:
35c2aa4f
VZ
709 Don't include the trailing separator in the returned string. This is
710 the default (the value of this flag is 0) and exists only for symmetry
711 with wxPATH_GET_SEPARATOR.
76ba33d3
VS
712
713 @note If the path is a toplevel one (e.g. @c "/" on Unix or @c "C:\" on
714 Windows), then the returned path will contain trailing separator
715 even with @c wxPATH_NO_SEPARATOR.
23324ae1
FM
716 */
717 wxString GetPath(int flags = wxPATH_GET_VOLUME,
328f5751 718 wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
719
720 /**
0b70c946
FM
721 Returns the usually used path separator for this format.
722 For all formats but @c wxPATH_DOS there is only one path separator anyhow,
723 but for DOS there are two of them and the native one, i.e. the backslash
724 is returned by this method.
3c4f71cc 725
4cc4bfaf 726 @see GetPathSeparators()
23324ae1 727 */
920b92a3 728 static wxUniChar GetPathSeparator(wxPathFormat format = wxPATH_NATIVE);
23324ae1
FM
729
730 /**
0b70c946
FM
731 Returns the string containing all the path separators for this format.
732 For all formats but @c wxPATH_DOS this string contains only one character
733 but for DOS and Windows both @c '/' and @c '\' may be used as separators.
3c4f71cc 734
4cc4bfaf 735 @see GetPathSeparator()
23324ae1
FM
736 */
737 static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE);
738
739 /**
0b70c946
FM
740 Returns the string of characters which may terminate the path part.
741 This is the same as GetPathSeparators() except for VMS
23324ae1
FM
742 path format where ] is used at the end of the path part.
743 */
744 static wxString GetPathTerminators(wxPathFormat format = wxPATH_NATIVE);
745
746 /**
0b70c946
FM
747 Returns the path with the trailing separator, useful for appending the name
748 to the given path.
749
750 This is the same as calling
751 @code
752 GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format)
753 @endcode
23324ae1 754 */
328f5751 755 wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
756
757 /**
758 Return the short form of the path (returns identity on non-Windows platforms).
759 */
328f5751 760 wxString GetShortPath() const;
23324ae1 761
23324ae1 762 /**
ca4bcd88
RR
763 Returns the size of the file If the file does not exist or its size could
764 not be read (because e.g. the file is locked by another process) the returned
0b70c946 765 value is ::wxInvalidSize.
23324ae1 766 */
adaaa686 767 wxULongLong GetSize() const;
0b70c946 768
ca4bcd88
RR
769 /**
770 Returns the size of the file If the file does not exist or its size could
771 not be read (because e.g. the file is locked by another process) the returned
0b70c946 772 value is ::wxInvalidSize.
ca4bcd88 773 */
882678eb 774 static wxULongLong GetSize(const wxString& filename);
23324ae1
FM
775
776 /**
777 Returns the directory used for temporary files.
778 */
779 static wxString GetTempDir();
780
781 /**
0b70c946
FM
782 Returns the last access, last modification and creation times.
783 The last access time is updated whenever the file is read or written
784 (or executed in the case of Windows), last modification time is only
785 changed when the file is written to.
786 Finally, the creation time is indeed the time when the file was created
23324ae1
FM
787 under Windows and the inode change time under Unix (as it is impossible to
788 retrieve the real file creation time there anyhow) which can also be changed
789 by many operations after the file creation.
0b70c946 790
23324ae1 791 If no filename or extension is specified in this instance of wxFileName
0b70c946
FM
792 (and therefore IsDir() returns @true) then this function will return the
793 directory times of the path specified by GetPath(), otherwise the file
794 times of the file specified by GetFullPath().
795 Any of the pointers may be @NULL if the corresponding time is not needed.
3c4f71cc 796
d29a9a8a 797 @return @true on success, @false if we failed to retrieve the times.
23324ae1
FM
798 */
799 bool GetTimes(wxDateTime* dtAccess, wxDateTime* dtMod,
328f5751 800 wxDateTime* dtCreate) const;
23324ae1
FM
801
802 /**
803 Returns the string containing the volume for this file name, empty if it
0b70c946
FM
804 doesn't have one or if the file system doesn't support volumes at all
805 (for example, Unix).
23324ae1 806 */
328f5751 807 wxString GetVolume() const;
23324ae1
FM
808
809 /**
810 Returns the string separating the volume from the path for this format.
811 */
812 static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE);
813
35c2aa4f
VZ
814 /**
815 This function builds a volume path string, for example "C:\\".
816
817 Implemented for the platforms which use drive letters, i.e. DOS, MSW
818 and OS/2 only.
819
820 @since 2.9.0
821
822 @param drive
0b70c946 823 The drive letter, 'A' through 'Z' or 'a' through 'z'.
35c2aa4f
VZ
824
825 @param flags
0b70c946
FM
826 @c wxPATH_NO_SEPARATOR or @c wxPATH_GET_SEPARATOR to omit or include
827 the trailing path separator, the default is to include it.
35c2aa4f
VZ
828
829 @return Volume path string.
830 */
831 static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);
832
23324ae1
FM
833 /**
834 Returns @true if an extension is present.
835 */
328f5751 836 bool HasExt() const;
23324ae1
FM
837
838 /**
839 Returns @true if a name is present.
840 */
328f5751 841 bool HasName() const;
23324ae1
FM
842
843 /**
844 Returns @true if a volume specifier is present.
845 */
328f5751 846 bool HasVolume() const;
23324ae1
FM
847
848 /**
6aa4e398
VZ
849 Inserts a directory component before the zero-based position in the
850 directory list.
851
852 As with AppendDir(), @a dir must be a single directory name and the
853 function returns @false and does nothing else if it isn't.
854
855 Notice that the return value is only available in wxWidgets 2.9.5 or
856 later.
23324ae1 857 */
6aa4e398 858 bool InsertDir(size_t before, const wxString& dir);
23324ae1
FM
859
860 /**
861 Returns @true if this filename is absolute.
862 */
2bd56258 863 bool IsAbsolute(wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
864
865 /**
866 Returns @true if the file names of this type are case-sensitive.
867 */
868 static bool IsCaseSensitive(wxPathFormat format = wxPATH_NATIVE);
869
870 /**
871 Returns @true if this object represents a directory, @false otherwise
0b70c946
FM
872 (i.e. if it is a file).
873
874 Note that this method doesn't test whether the directory or file really
875 exists, you should use DirExists() or FileExists() for this.
23324ae1 876 */
328f5751 877 bool IsDir() const;
23324ae1 878
23324ae1 879 /**
2bd56258
RR
880 Returns @true if the directory component of this instance is an existing
881 directory and this process has read permissions on it. Read permissions
882 on a directory mean that you can list the directory contents but it
23324ae1
FM
883 doesn't imply that you have read permissions on the files contained.
884 */
2bd56258 885 bool IsDirReadable() const;
0b70c946 886
2bd56258
RR
887 /**
888 Returns @true if the given @e dir is an existing directory and this process
889 has read permissions on it. Read permissions on a directory mean that you
890 can list the directory contents but it doesn't imply that you have read
891 permissions on the files contained.
892 */
893 static bool IsDirReadable(const wxString& dir);
23324ae1 894
23324ae1 895 /**
2bd56258 896 Returns @true if the directory component of this instance
23324ae1
FM
897 is an existing directory and this process has write permissions on it.
898 Write permissions on a directory mean that you can create new files in the
899 directory.
900 */
2bd56258 901 bool IsDirWritable() const;
0b70c946 902
2bd56258 903 /**
0b70c946
FM
904 Returns @true if the given @a dir is an existing directory and this
905 process has write permissions on it.
2bd56258
RR
906 Write permissions on a directory mean that you can create new files in the
907 directory.
908 */
909 static bool IsDirWritable(const wxString& dir);
23324ae1 910
23324ae1
FM
911 /**
912 Returns @true if a file with this name exists and if this process has execute
913 permissions on it.
914 */
2bd56258 915 bool IsFileExecutable() const;
0b70c946 916
2bd56258
RR
917 /**
918 Returns @true if a file with this name exists and if this process has execute
919 permissions on it.
920 */
921 static bool IsFileExecutable(const wxString& file);
23324ae1 922
23324ae1
FM
923 /**
924 Returns @true if a file with this name exists and if this process has read
925 permissions on it.
926 */
2bd56258 927 bool IsFileReadable() const;
0b70c946 928
2bd56258
RR
929 /**
930 Returns @true if a file with this name exists and if this process has read
931 permissions on it.
932 */
933 static bool IsFileReadable(const wxString& file);
23324ae1 934
23324ae1
FM
935 /**
936 Returns @true if a file with this name exists and if this process has write
937 permissions on it.
938 */
2bd56258 939 bool IsFileWritable() const;
0b70c946 940
2bd56258
RR
941 /**
942 Returns @true if a file with this name exists and if this process has write
943 permissions on it.
944 */
945 static bool IsFileWritable(const wxString& file);
23324ae1
FM
946
947 /**
0b70c946
FM
948 Returns @true if the filename is valid, @false if it is not initialized yet.
949 The assignment functions and Clear() may reset the object to the uninitialized,
23324ae1
FM
950 invalid state (the former only do it on failure).
951 */
328f5751 952 bool IsOk() const;
23324ae1
FM
953
954 /**
955 Returns @true if the char is a path separator for this format.
956 */
957 static bool IsPathSeparator(wxChar ch,
958 wxPathFormat format = wxPATH_NATIVE);
959
e01a788e
VZ
960 /**
961 Returns @true if the volume part of the path is a unique volume name.
962
963 This function will always return @false if the path format is not
964 wxPATH_DOS.
965
966 Unique volume names are Windows volume identifiers which remain the same
967 regardless of where the volume is actually mounted. Example of a path
968 using a volume name could be
969 @code
970 \\?\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\Program Files\setup.exe
971 @endcode
972
973 @since 2.9.1
974 */
975 static bool IsMSWUniqueVolumeNamePath(const wxString& path,
976 wxPathFormat format = wxPATH_NATIVE);
977
23324ae1
FM
978 /**
979 Returns @true if this filename is not absolute.
980 */
2bd56258 981 bool IsRelative(wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
982
983 /**
984 On Mac OS, gets the common type and creator for the given extension.
ccca2121
VZ
985
986 @onlyfor{wxosx}
23324ae1
FM
987 */
988 static bool MacFindDefaultTypeAndCreator(const wxString& ext,
0b70c946
FM
989 wxUint32* type,
990 wxUint32* creator);
23324ae1
FM
991
992 /**
0b70c946
FM
993 On Mac OS, registers application defined extensions and their default type
994 and creator.
ccca2121
VZ
995
996 @onlyfor{wxosx}
23324ae1
FM
997 */
998 static void MacRegisterDefaultTypeAndCreator(const wxString& ext,
0b70c946
FM
999 wxUint32 type,
1000 wxUint32 creator);
23324ae1
FM
1001
1002 /**
0b70c946
FM
1003 On Mac OS, looks up the appropriate type and creator from the registration
1004 and then sets it.
ccca2121
VZ
1005
1006 @onlyfor{wxosx}
23324ae1
FM
1007 */
1008 bool MacSetDefaultTypeAndCreator();
1009
1010 /**
0b70c946
FM
1011 Make the file name absolute.
1012 This is a shortcut for
1013 @code
1014 wxFileName::Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE |
1015 wxPATH_NORM_TILDE, cwd, format)
1016 @endcode
3c4f71cc 1017
4cc4bfaf 1018 @see MakeRelativeTo(), Normalize(), IsAbsolute()
23324ae1
FM
1019 */
1020 bool MakeAbsolute(const wxString& cwd = wxEmptyString,
1021 wxPathFormat format = wxPATH_NATIVE);
1022
1023 /**
7c913512 1024 This function tries to put this file name in a form relative to
0b70c946
FM
1025 @a pathBase.
1026 In other words, it returns the file name which should be used to access
1027 this file if the current directory were pathBase.
3c4f71cc 1028
76e9224e 1029 @param pathBase
0b70c946 1030 The directory to use as root, current directory is used by default
7c913512 1031 @param format
0b70c946 1032 The file name format, native by default
3c4f71cc 1033
d29a9a8a 1034 @return @true if the file name has been changed, @false if we failed to do
0b70c946
FM
1035 anything with it (currently this only happens if the file name
1036 is on a volume different from the volume specified by @a pathBase).
3c4f71cc 1037
4cc4bfaf 1038 @see Normalize()
23324ae1
FM
1039 */
1040 bool MakeRelativeTo(const wxString& pathBase = wxEmptyString,
1041 wxPathFormat format = wxPATH_NATIVE);
1042
23324ae1 1043 /**
ca4bcd88 1044 Creates a directory.
0b70c946
FM
1045
1046 @param perm
f41d6c8c 1047 The permissions for the newly created directory.
b91c4601 1048 See the ::wxPosixPermissions enumeration for more info.
ca4bcd88 1049 @param flags
0b70c946
FM
1050 If the flags contain @c wxPATH_MKDIR_FULL flag, try to create each
1051 directory in the path and also don't return an error if the target
1052 directory already exists.
ca4bcd88
RR
1053
1054 @return Returns @true if the directory was successfully created, @false
0b70c946 1055 otherwise.
ca4bcd88 1056 */
89391a4e 1057 bool Mkdir(int perm = wxS_DIR_DEFAULT, int flags = 0) const;
0b70c946 1058
ca4bcd88
RR
1059 /**
1060 Creates a directory.
0b70c946 1061
7c913512 1062 @param dir
f41d6c8c 1063 The directory to create
76e9224e 1064 @param perm
f41d6c8c 1065 The permissions for the newly created directory.
b91c4601 1066 See the ::wxPosixPermissions enumeration for more info.
7c913512 1067 @param flags
f41d6c8c 1068 If the flags contain @c wxPATH_MKDIR_FULL flag, try to create each
0b70c946
FM
1069 directory in the path and also don't return an error if the target
1070 directory already exists.
3c4f71cc 1071
d29a9a8a 1072 @return Returns @true if the directory was successfully created, @false
0b70c946 1073 otherwise.
23324ae1 1074 */
f41d6c8c 1075 static bool Mkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT,
7c913512 1076 int flags = 0);
23324ae1
FM
1077
1078 /**
fcf56ee4
VZ
1079 Normalize the path.
1080
1081 With the default flags value, the path will be made absolute, without
1082 any ".." and "." and all environment variables will be expanded in it.
1083
1084 Notice that in some rare cases normalizing a valid path may result in
1085 an invalid wxFileName object. E.g. normalizing "./" path using
1086 wxPATH_NORM_DOTS but not wxPATH_NORM_ABSOLUTE will result in a
1087 completely empty and thus invalid object. As long as there is a non
1088 empty file name the result of normalization will be valid however.
3c4f71cc 1089
7c913512 1090 @param flags
4cc4bfaf 1091 The kind of normalization to do with the file name. It can be
992ff331 1092 any or-combination of the ::wxPathNormalize enumeration values.
4cc4bfaf
FM
1093 @param cwd
1094 If not empty, this directory will be used instead of current
0b70c946 1095 working directory in normalization (see @c wxPATH_NORM_ABSOLUTE).
7c913512 1096 @param format
4cc4bfaf 1097 The file name format to use when processing the paths, native by default.
3c4f71cc 1098
d29a9a8a 1099 @return @true if normalization was successfully or @false otherwise.
23324ae1
FM
1100 */
1101 bool Normalize(int flags = wxPATH_NORM_ALL,
1102 const wxString& cwd = wxEmptyString,
1103 wxPathFormat format = wxPATH_NATIVE);
1104
23324ae1 1105 /**
0b70c946
FM
1106 Prepends a directory to the file path.
1107 Please see AppendDir() for important notes.
23324ae1
FM
1108 */
1109 void PrependDir(const wxString& dir);
1110
1111 /**
1112 Removes the specified directory component from the path.
3c4f71cc 1113
4cc4bfaf 1114 @see GetDirCount()
23324ae1
FM
1115 */
1116 void RemoveDir(size_t pos);
1117
1118 /**
1119 Removes last directory component from the path.
1120 */
1121 void RemoveLastDir();
1122
395f3aa8
FM
1123 /**
1124 If the path contains the value of the environment variable named @a envname
1125 then this function replaces it with the string obtained from
1126 wxString::Format(replacementFmtString, value_of_envname_variable).
1127
1128 This function is useful to make the path shorter or to make it dependent
1129 from a certain environment variable.
1130 Normalize() with @c wxPATH_NORM_ENV_VARS can perform the opposite of this
1131 function (depending on the value of @a replacementFmtString).
1132
1133 The name and extension of this filename are not modified.
1134
1135 Example:
1136 @code
1137 wxFileName fn("/usr/openwin/lib/someFile");
1138 fn.ReplaceEnvVariable("OPENWINHOME");
1139 // now fn.GetFullPath() == "$OPENWINHOME/lib/someFile"
1140 @endcode
1141
1142 @since 2.9.0
1143
1144 @return @true if the operation was successful (which doesn't mean
1145 that something was actually replaced, just that ::wxGetEnv
1146 didn't fail).
1147 */
1148 bool ReplaceEnvVariable(const wxString& envname,
1149 const wxString& replacementFmtString = "$%s",
1150 wxPathFormat format = wxPATH_NATIVE);
1151
1152 /**
1153 Replaces, if present in the path, the home directory for the given user
1154 (see ::wxGetHomeDir) with a tilde (~).
1155
1156 Normalize() with @c wxPATH_NORM_TILDE performs the opposite of this
1157 function.
1158
1159 The name and extension of this filename are not modified.
1160
1161 @since 2.9.0
1162
1163 @return @true if the operation was successful (which doesn't mean
1164 that something was actually replaced, just that ::wxGetHomeDir
1165 didn't fail).
1166 */
1167 bool ReplaceHomeDir(wxPathFormat format = wxPATH_NATIVE);
1168
1169
23324ae1
FM
1170 /**
1171 Deletes the specified directory from the file system.
110c5094
VZ
1172
1173 @param flags
1174 Can contain one of wxPATH_RMDIR_FULL or wxPATH_RMDIR_RECURSIVE. By
1175 default contains neither so the directory will not be removed
1176 unless it is empty.
1177
1178 @return Returns @true if the directory was successfully deleted, @false
1179 otherwise.
23324ae1 1180 */
89391a4e 1181 bool Rmdir(int flags = 0) const;
0b70c946 1182
2bd56258
RR
1183 /**
1184 Deletes the specified directory from the file system.
110c5094
VZ
1185
1186 @param dir
1187 The directory to delete
1188 @param flags
1189 Can contain one of wxPATH_RMDIR_FULL or wxPATH_RMDIR_RECURSIVE. By
1190 default contains neither so the directory will not be removed
1191 unless it is empty.
1192
1193 @return Returns @true if the directory was successfully deleted, @false
1194 otherwise.
2bd56258 1195 */
110c5094 1196 static bool Rmdir(const wxString& dir, int flags = 0);
23324ae1
FM
1197
1198 /**
1199 Compares the filename using the rules of this platform.
1200 */
1201 bool SameAs(const wxFileName& filepath,
328f5751 1202 wxPathFormat format = wxPATH_NATIVE) const;
23324ae1 1203
23324ae1
FM
1204 /**
1205 Changes the current working directory.
1206 */
d9e80dce 1207 bool SetCwd() const;
0b70c946 1208
2bd56258
RR
1209 /**
1210 Changes the current working directory.
1211 */
7c913512 1212 static bool SetCwd(const wxString& cwd);
23324ae1
FM
1213
1214 /**
7c913512
FM
1215 Sets the extension of the file name to be an empty extension.
1216 This is different from having no extension at all as the file
23324ae1 1217 name will have a trailing dot after a call to this method.
3c4f71cc 1218
4cc4bfaf 1219 @see SetExt(), ClearExt()
23324ae1
FM
1220 */
1221 void SetEmptyExt();
1222
1223 /**
0b70c946
FM
1224 Sets the extension of the file name.
1225
1226 Setting an empty string as the extension will remove the extension
1227 resulting in a file name without a trailing dot, unlike a call to
23324ae1 1228 SetEmptyExt().
3c4f71cc 1229
4cc4bfaf 1230 @see SetEmptyExt(), ClearExt()
23324ae1
FM
1231 */
1232 void SetExt(const wxString& ext);
1233
1234 /**
1235 The full name is the file name and extension (but without the path).
1236 */
1237 void SetFullName(const wxString& fullname);
1238
1239 /**
1240 Sets the name part (without extension).
3c4f71cc 1241
4cc4bfaf 1242 @see SetFullName()
23324ae1
FM
1243 */
1244 void SetName(const wxString& name);
1245
cb755cb7 1246 /**
824216af 1247 Sets the path.
cb755cb7 1248
824216af
VZ
1249 The @a path argument includes both the path and the volume, if
1250 supported by @a format.
1251
1252 Calling this function doesn't affect the name and extension components,
1253 to change them as well you can use Assign() or just an assignment
1254 operator.
cb755cb7
VZ
1255
1256 @see GetPath()
1257 */
1258 void SetPath(const wxString& path, wxPathFormat format = wxPATH_NATIVE);
1259
23324ae1
FM
1260 /**
1261 Sets the file creation and last access/modification times (any of the pointers
1262 may be @NULL).
1263 */
1264 bool SetTimes(const wxDateTime* dtAccess,
1265 const wxDateTime* dtMod,
d9e80dce 1266 const wxDateTime* dtCreate) const;
23324ae1
FM
1267
1268 /**
1269 Sets the volume specifier.
1270 */
1271 void SetVolume(const wxString& volume);
1272
c063adeb
VZ
1273 /**
1274 Return whether some operations will follow symlink.
1275
1276 By default, file operations "follow symlink", i.e. operate on its
1277 target and not on the symlink itself. See DontFollowLink() for more
1278 information.
1279
1280 @since 2.9.5
1281 */
1282 bool ShouldFollowLink() const;
1283
23324ae1
FM
1284 //@{
1285 /**
1286 This function splits a full file name into components: the volume (with the
1287 first version) path (including the volume in the second version), the base name
0b70c946
FM
1288 and the extension.
1289
1290 Any of the output parameters (@e volume, @e path, @a name or @e ext) may
1291 be @NULL if you are not interested in the value of a particular component.
1292 Also, @a fullpath may be empty on entry.
4cc4bfaf
FM
1293 On return, @a path contains the file path (without the trailing separator),
1294 @a name contains the file name and @a ext contains the file extension
23324ae1
FM
1295 without leading dot. All three of them may be empty if the corresponding
1296 component is. The old contents of the strings pointed to by these parameters
1297 will be overwritten in any case (if the pointers are not @NULL).
0b70c946 1298
cdbcf4c2 1299 Note that for a filename "foo." the extension is present, as indicated by the
7c913512 1300 trailing dot, but empty. If you need to cope with such cases, you should use
4cc4bfaf 1301 @a hasExt instead of relying on testing whether @a ext is empty or not.
23324ae1 1302 */
882678eb
FM
1303 static void SplitPath(const wxString& fullpath,
1304 wxString* volume,
23324ae1
FM
1305 wxString* path,
1306 wxString* name,
1307 wxString* ext,
882678eb 1308 bool* hasExt = NULL,
23324ae1 1309 wxPathFormat format = wxPATH_NATIVE);
7c913512
FM
1310 static void SplitPath(const wxString& fullpath,
1311 wxString* volume,
1312 wxString* path,
1313 wxString* name,
1314 wxString* ext,
882678eb 1315 wxPathFormat format);
7c913512
FM
1316 static void SplitPath(const wxString& fullpath,
1317 wxString* path,
1318 wxString* name,
1319 wxString* ext,
1320 wxPathFormat format = wxPATH_NATIVE);
23324ae1
FM
1321 //@}
1322
1323 /**
4cc4bfaf 1324 Splits the given @a fullpath into the volume part (which may be empty) and
23324ae1 1325 the pure path part, not containing any volume.
3c4f71cc 1326
4cc4bfaf 1327 @see SplitPath()
23324ae1
FM
1328 */
1329 static void SplitVolume(const wxString& fullpath,
1330 wxString* volume,
1331 wxString* path,
1332 wxPathFormat format = wxPATH_NATIVE);
1333
181dd701
VZ
1334
1335 /**
1336 Strip the file extension.
1337
1338 This function does more than just removing everything after the last
1339 period from the string, for example it will return the string ".vimrc"
1340 unchanged because the part after the period is not an extension but the
1341 file name in this case. You can use wxString::BeforeLast() to really
1342 get just the part before the last period (but notice that that function
1343 returns empty string if period is not present at all unlike this
1344 function which returns the @a fullname unchanged in this case).
1345
1346 @param fullname
1347 File path including name and, optionally, extension.
1348
1349 @return
1350 File path without extension
1351
1352 @since 2.9.0
1353 */
1354 static wxString StripExtension(const wxString& fullname);
1355
23324ae1
FM
1356 /**
1357 Sets the access and modification times to the current moment.
1358 */
d9e80dce 1359 bool Touch() const;
23324ae1 1360
23324ae1
FM
1361 /**
1362 Returns @true if the filenames are different. The string @e filenames
1363 is interpreted as a path in the native filename format.
1364 */
0b70c946
FM
1365 bool operator!=(const wxFileName& filename) const;
1366
2bd56258
RR
1367 /**
1368 Returns @true if the filenames are different. The string @e filenames
1369 is interpreted as a path in the native filename format.
1370 */
0b70c946 1371 bool operator!=(const wxString& filename) const;
23324ae1 1372
23324ae1 1373 /**
0b70c946
FM
1374 Returns @true if the filenames are equal. The string @e filenames is
1375 interpreted as a path in the native filename format.
2bd56258 1376 */
0b70c946 1377 bool operator==(const wxFileName& filename) const;
23324ae1 1378
23324ae1
FM
1379 /**
1380 Returns @true if the filenames are equal. The string @e filenames is
1381 interpreted as a path in the native filename format.
1382 */
0b70c946
FM
1383 bool operator==(const wxString& filename) const;
1384
2bd56258 1385 /**
0b70c946
FM
1386 Assigns the new value to this filename object.
1387 */
1388 wxFileName& operator=(const wxFileName& filename);
1389
1390 /**
1391 Assigns the new value to this filename object.
2bd56258 1392 */
0b70c946 1393 wxFileName& operator=(const wxString& filename);
23324ae1 1394};