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