]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/filename.h
Removed wxPG_EX_LEGACY_VALIDATORS
[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$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
0b70c946
FM
9
10/** The various values for the path format: this mainly affects the path
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
30
31/** The kind of normalization to do with the file name: these values can be
32 or'd together to perform several operations at once.
33 See wxFileName::Normalize() for more info.
34*/
35enum wxPathNormalize
36{
37 wxPATH_NORM_ENV_VARS = 0x0001, //!< replace env vars with their values.
38 wxPATH_NORM_DOTS = 0x0002, //!< squeeze all .. and . and prepend cwd.
39 wxPATH_NORM_TILDE = 0x0004, //!< Unix only: replace ~ and ~user.
40 wxPATH_NORM_CASE = 0x0008, //!< if case insensitive => tolower.
41 wxPATH_NORM_ABSOLUTE = 0x0010, //!< make the path absolute.
42 wxPATH_NORM_LONG = 0x0020, //!< make the path the long form.
43 wxPATH_NORM_SHORTCUT = 0x0040, //!< resolve the shortcut, if it is a shortcut.
44 wxPATH_NORM_ALL = 0x00ff & ~wxPATH_NORM_CASE
45};
46
47/**
48 The return value of wxFileName::GetSize() in case of error.
49*/
50wxULongLong wxInvalidSize;
51
52
23324ae1
FM
53/**
54 @class wxFileName
7c913512 55
23324ae1
FM
56 wxFileName encapsulates a file name. This class serves two purposes: first, it
57 provides the functions to split the file names into components and to recombine
58 these components in the full file name which can then be passed to the OS file
59 functions (and @ref overview_filefunctions "wxWidgets functions" wrapping them).
60 Second, it includes the functions for working with the files itself. Note that
61 to change the file data you should use wxFile class instead.
62 wxFileName provides functions for working with the file attributes.
7c913512 63
23324ae1
FM
64 When working with directory names (i.e. without filename and extension)
65 make sure not to misuse the file name part of this class with the last
66 directory. Instead initialize the wxFileName instance like this:
7c913512 67
23324ae1
FM
68 @code
69 wxFileName dirname( "C:\mydir", "" );
70 MyMethod( dirname.GetPath() );
71 @endcode
7c913512 72
0b70c946 73 The same can be done using the static method wxFileName::DirName():
7c913512 74
23324ae1
FM
75 @code
76 wxFileName dirname = wxFileName::DirName( "C:\mydir" );
77 MyMethod( dirname.GetPath() );
78 @endcode
7c913512 79
0b70c946
FM
80 Accordingly, methods dealing with directories or directory names like
81 wxFileName::IsDirReadable() use wxFileName::GetPath() whereas methods dealing
82 with file names like wxFileName::IsFileReadable() use wxFileName::GetFullPath().
7c913512 83
0b70c946
FM
84 If it is not known wether a string contains a directory name or a complete
85 file name (such as when interpreting user input) you need to use the static
86 function wxFileName::DirExists() (or its identical variants wxDir::Exists() and
87 wxDirExists()) and construct the wxFileName instance accordingly.
88 This will only work if the directory actually exists, of course:
7c913512 89
23324ae1
FM
90 @code
91 wxString user_input;
92 // get input from user
7c913512 93
23324ae1
FM
94 wxFileName fname;
95 if (wxDirExists(user_input))
96 fname.AssignDir( user_input );
97 else
98 fname.Assign( user_input );
99 @endcode
7c913512 100
0b70c946
FM
101 Please note that many wxFileName methods accept the path format argument
102 which is by @c wxPATH_NATIVE by default meaning to use the path format
103 native for the current platform.
104 The path format affects the operation of wxFileName functions in several ways:
105 first and foremost, it defines the path separator character to use, but it
106 also affects other things such as whether the path has the drive part or not.
107 See wxPathFormat for more info.
108
109
110 @section filename_format File name format
111
112 wxFileName currently supports the file names in the Unix, DOS/Windows,
113 Mac OS and VMS formats. Although these formats are quite different,
114 wxFileName tries to treat them all in the same generic way.
115 It supposes that all file names consist of the following parts: the volume
116 (also known as drive under Windows or device under VMS), the path which is
117 a sequence of directory names separated by the path separators and the full
118 filename itself which, in turn, is composed from the base file name and the
119 extension. All of the individual components of the file name may be empty
120 and, for example, the volume name is always empty under Unix, but if they
121 are all empty simultaneously, the filename object is considered to be in an
122 invalid state and wxFileName::IsOk() returns false for it.
123
124 File names can be case-sensitive or not, the function wxFileName::IsCaseSensitive()
125 allows to determine this. The rules for determining whether the file name is
126 absolute or relative also depend on the file name format and the only portable way
127 to answer this question is to use wxFileName::IsAbsolute() or wxFileName::IsRelative()
128 method.
129
130 Note that on Windows,"X:" refers to the current working directory on drive X.
131 Therefore, a wxFileName instance constructed from for example "X:dir/file.ext"
132 treats the portion beyond drive separator as being relative to that directory.
133 To ensure that the filename is absolute, you may use wxFileName::MakeAbsolute().
134 There is also an inverse function wxFileName::MakeRelativeTo() which undoes
135 what wxFileName::Normalize(wxPATH_NORM_DOTS) does.
136 Other functions returning information about the file format provided by this
137 class are wxFileName::GetVolumeSeparator(), wxFileName::IsPathSeparator().
138
139
140 @section filename_construction File name construction
141
142 You can initialize a wxFileName instance using one of the following functions:
143
144 @li wxFileName::wxFileName()
145 @li wxFileName::Assign()
146 @li wxFileName::AssignCwd()
147 @li wxFileName::AssignDir()
148 @li wxFileName::AssignHomeDir()
149 @li wxFileName::DirName()
150 @li wxFileName::FileName()
151 @li wxFileName::operator=()
152
153
154 @section filename_tests File name tests
155
156 Before doing other tests, you should use wxFileName::IsOk() to verify that
157 the filename is well defined. If it is, FileExists() can be used to test whether
158 a file with such name exists and wxFileName::DirExists() can be used to test
159 for directory existence.
160 File names should be compared using the wxFileName::SameAs() method or
161 wxFileName::operator==(). For testing basic access modes, you can use:
162
163 @li wxFileName::IsDirWritable()
164 @li wxFileName::IsDirReadable()
165 @li wxFileName::IsFileWritable()
166 @li wxFileName::IsFileReadable()
167 @li wxFileName::IsFileExecutable()
168
169
170 @section filename_components File name components
171
172 These functions allow to examine and modify the individual directories
173 of the path:
174
175 @li wxFileName::AppendDir()
176 @li wxFileName::InsertDir()
177 @li wxFileName::GetDirCount()
178 @li wxFileName::PrependDir()
179 @li wxFileName::RemoveDir()
180 @li wxFileName::RemoveLastDir()
181
182 To change the components of the file name individually you can use the
183 following functions:
184
185 @li wxFileName::GetExt()
186 @li wxFileName::GetName()
187 @li wxFileName::GetVolume()
188 @li wxFileName::HasExt()
189 @li wxFileName::HasName()
190 @li wxFileName::HasVolume()
191 @li wxFileName::SetExt()
192 @li wxFileName::ClearExt()
193 @li wxFileName::SetEmptyExt()
194 @li wxFileName::SetName()
195 @li wxFileName::SetVolume()
196
197 You can initialize a wxFileName instance using one of the following functions:
198
199
200 @section filename_operations File name operations
201
202 These methods allow to work with the file creation, access and modification
203 times. Note that not all filesystems under all platforms implement these times
204 in the same way. For example, the access time under Windows has a resolution of
205 one day (so it is really the access date and not time). The access time may be
206 updated when the file is executed or not depending on the platform.
207
208 @li wxFileName::GetModificationTime()
209 @li wxFileName::GetTimes()
210 @li wxFileName::SetTimes()
211 @li wxFileName::Touch()
212
213 Other file system operations functions are:
214
215 @li wxFileName::Mkdir()
216 @li wxFileName::Rmdir()
ca4bcd88
RR
217
218
23324ae1
FM
219 @library{wxbase}
220 @category{file}
23324ae1 221*/
7c913512 222class wxFileName
23324ae1
FM
223{
224public:
23324ae1 225 /**
ca4bcd88 226 Default constructor.
23324ae1
FM
227 */
228 wxFileName();
0b70c946 229
ca4bcd88
RR
230 /**
231 Copy constructor.
232 */
7c913512 233 wxFileName(const wxFileName& filename);
0b70c946 234
ca4bcd88 235 /**
0b70c946
FM
236 Constructor taking a full filename.
237
238 If it terminates with a '/', a directory path is constructed
239 (the name will be empty), otherwise a file name and extension
240 are extracted from it.
ca4bcd88 241 */
7c913512
FM
242 wxFileName(const wxString& fullpath,
243 wxPathFormat format = wxPATH_NATIVE);
0b70c946 244
ca4bcd88
RR
245 /**
246 Constructor a directory name and file name.
247 */
7c913512
FM
248 wxFileName(const wxString& path, const wxString& name,
249 wxPathFormat format = wxPATH_NATIVE);
0b70c946 250
ca4bcd88
RR
251 /**
252 Constructor from a directory name, base file name and extension.
253 */
7c913512
FM
254 wxFileName(const wxString& path, const wxString& name,
255 const wxString& ext,
256 wxPathFormat format = wxPATH_NATIVE);
0b70c946 257
ca4bcd88
RR
258 /**
259 Constructor from a volume name, a directory name, base file name and extension.
260 */
7c913512
FM
261 wxFileName(const wxString& volume, const wxString& path,
262 const wxString& name,
263 const wxString& ext,
264 wxPathFormat format = wxPATH_NATIVE);
23324ae1
FM
265
266 /**
267 Appends a directory component to the path. This component should contain a
268 single directory name level, i.e. not contain any path or volume separators nor
269 should it be empty, otherwise the function does nothing (and generates an
270 assert failure in debug build).
271 */
272 void AppendDir(const wxString& dir);
273
23324ae1 274 /**
ca4bcd88 275 Creates the file name from another filename object.
23324ae1
FM
276 */
277 void Assign(const wxFileName& filepath);
0b70c946 278
ca4bcd88
RR
279 /**
280 Creates the file name from a full file name with a path.
281 */
7c913512
FM
282 void Assign(const wxString& fullpath,
283 wxPathFormat format = wxPATH_NATIVE);
0b70c946 284
ca4bcd88
RR
285 /**
286 Creates the file name from volumne, path, name and extension.
287 */
7c913512
FM
288 void Assign(const wxString& volume, const wxString& path,
289 const wxString& name,
290 const wxString& ext,
291 bool hasExt,
292 wxPathFormat format = wxPATH_NATIVE);
0b70c946 293
ca4bcd88
RR
294 /**
295 Creates the file name from volumne, path, name and extension.
296 */
7c913512
FM
297 void Assign(const wxString& volume, const wxString& path,
298 const wxString& name,
299 const wxString& ext,
300 wxPathFormat format = wxPATH_NATIVE);
0b70c946 301
ca4bcd88
RR
302 /**
303 Creates the file name from file path and file name.
304 */
7c913512
FM
305 void Assign(const wxString& path, const wxString& name,
306 wxPathFormat format = wxPATH_NATIVE);
0b70c946 307
ca4bcd88
RR
308 /**
309 Creates the file name from path, name and extension.
310 */
7c913512
FM
311 void Assign(const wxString& path, const wxString& name,
312 const wxString& ext,
313 wxPathFormat format = wxPATH_NATIVE);
23324ae1
FM
314
315 /**
316 Makes this object refer to the current working directory on the specified
4cc4bfaf 317 volume (or current volume if @a volume is empty).
3c4f71cc 318
4cc4bfaf 319 @see GetCwd()
23324ae1
FM
320 */
321 static void AssignCwd(const wxString& volume = wxEmptyString);
322
323 /**
0b70c946
FM
324 Sets this file name object to the given directory name.
325 The name and extension will be empty.
23324ae1
FM
326 */
327 void AssignDir(const wxString& dir,
328 wxPathFormat format = wxPATH_NATIVE);
329
330 /**
331 Sets this file name object to the home directory.
332 */
333 void AssignHomeDir();
334
335 /**
0b70c946
FM
336 The function calls CreateTempFileName() to create a temporary file
337 and sets this object to the name of the file.
338 If a temporary file couldn't be created, the object is put into
339 an invalid state (see IsOk())
23324ae1
FM
340 */
341 void AssignTempFileName(const wxString& prefix,
4cc4bfaf 342 wxFile* fileTemp = NULL);
23324ae1
FM
343
344 /**
345 Reset all components to default, uninitialized state.
346 */
347 void Clear();
348
349 /**
7c913512 350 Removes the extension from the file name resulting in a
23324ae1 351 file name with no trailing dot.
3c4f71cc 352
4cc4bfaf 353 @see SetExt(), SetEmptyExt()
23324ae1 354 */
2bd56258 355 void ClearExt();
23324ae1
FM
356
357 /**
0b70c946
FM
358 Returns a temporary file name starting with the given @e prefix.
359 If the @a prefix is an absolute path, the temporary file is created in this
23324ae1
FM
360 directory, otherwise it is created in the default system directory for the
361 temporary files or in the current directory.
0b70c946
FM
362
363 If the function succeeds, the temporary file is actually created.
364 If @a fileTemp is not @NULL, this file will be opened using the name of
23324ae1
FM
365 the temporary file. When possible, this is done in an atomic way ensuring that
366 no race condition occurs between the temporary file name generation and opening
367 it which could often lead to security compromise on the multiuser systems.
4cc4bfaf 368 If @a fileTemp is @NULL, the file is only created, but not opened.
23324ae1
FM
369 Under Unix, the temporary file will have read and write permissions for the
370 owner only to minimize the security problems.
3c4f71cc 371
7c913512 372 @param prefix
4cc4bfaf 373 Prefix to use for the temporary file name construction
7c913512 374 @param fileTemp
4cc4bfaf 375 The file to open or @NULL to just get the name
3c4f71cc 376
d29a9a8a 377 @return The full temporary file name or an empty string on error.
23324ae1
FM
378 */
379 static wxString CreateTempFileName(const wxString& prefix,
4cc4bfaf 380 wxFile* fileTemp = NULL);
23324ae1 381
23324ae1
FM
382 /**
383 Returns @true if the directory with this name exists.
384 */
0b70c946
FM
385 bool DirExists() const;
386
ca4bcd88
RR
387 /**
388 Returns @true if the directory with this name exists.
389 */
0b70c946 390 static bool DirExists(const wxString& dir);
23324ae1
FM
391
392 /**
393 Returns the object corresponding to the directory with the given name.
4cc4bfaf 394 The @a dir parameter may have trailing path separator or not.
23324ae1
FM
395 */
396 static wxFileName DirName(const wxString& dir,
397 wxPathFormat format = wxPATH_NATIVE);
398
399 /**
ca4bcd88 400 Returns @true if the file with this name exists.
3c4f71cc 401
ca4bcd88 402 @see DirExists()
23324ae1 403 */
0b70c946
FM
404 bool FileExists() const;
405
23324ae1
FM
406 /**
407 Returns @true if the file with this name exists.
3c4f71cc 408
4cc4bfaf 409 @see DirExists()
23324ae1 410 */
0b70c946 411 static bool FileExists(const wxString& file);
23324ae1
FM
412
413 /**
414 Returns the file name object corresponding to the given @e file. This
415 function exists mainly for symmetry with DirName().
416 */
417 static wxFileName FileName(const wxString& file,
418 wxPathFormat format = wxPATH_NATIVE);
419
420 /**
0b70c946
FM
421 Retrieves the value of the current working directory on the specified volume.
422 If the volume is empty, the program's current working directory is returned for
423 the current volume.
3c4f71cc 424
d29a9a8a 425 @return The string containing the current working directory or an empty
0b70c946 426 string on error.
3c4f71cc 427
4cc4bfaf 428 @see AssignCwd()
23324ae1 429 */
0b70c946 430 static wxString GetCwd(const wxString& volume = wxEmptyString);
23324ae1
FM
431
432 /**
433 Returns the number of directories in the file name.
434 */
328f5751 435 size_t GetDirCount() const;
23324ae1
FM
436
437 /**
438 Returns the directories in string array form.
439 */
0b70c946 440 const wxArrayString& GetDirs() const;
23324ae1
FM
441
442 /**
443 Returns the file name extension.
444 */
328f5751 445 wxString GetExt() const;
23324ae1
FM
446
447 /**
0b70c946
FM
448 Returns the characters that can't be used in filenames and directory names
449 for the specified format.
23324ae1
FM
450 */
451 static wxString GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE);
452
453 /**
454 Returns the canonical path format for this platform.
455 */
456 static wxPathFormat GetFormat(wxPathFormat format = wxPATH_NATIVE);
457
458 /**
459 Returns the full name (including extension but excluding directories).
460 */
328f5751 461 wxString GetFullName() const;
23324ae1
FM
462
463 /**
464 Returns the full path with name and extension.
465 */
328f5751 466 wxString GetFullPath(wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
467
468 /**
469 Returns the home directory.
470 */
471 static wxString GetHomeDir();
472
23324ae1 473 /**
2bd56258 474 Returns the size of the file in a human-readable form.
0b70c946 475
2bd56258
RR
476 If the size could not be retrieved the @c failmsg string
477 is returned. In case of success, the returned string is
478 a floating-point number with @c precision decimal digits
479 followed by the size unit (B, kB, MB, GB, TB: respectively
480 bytes, kilobytes, megabytes, gigabytes, terabytes).
23324ae1
FM
481 */
482 wxString GetHumanReadableSize(const wxString& failmsg = "Not available",
0b70c946
FM
483 int precision = 1) const;
484
2bd56258
RR
485 /**
486 Returns the size of the given number of bytes in a human-readable form.
0b70c946
FM
487
488 If @a bytes is ::wxInvalidSize or zero, then @a nullsize is returned.
489
490 In case of success, the returned string is a floating-point number with
491 @a precision decimal digits followed by the size unit (B, kB, MB, GB,
2bd56258
RR
492 TB: respectively bytes, kilobytes, megabytes, gigabytes, terabytes).
493 */
0b70c946
FM
494 static wxString GetHumanReadableSize(const wxULongLong& bytes,
495 const wxString& nullsize = "Not available",
496 int precision = 1);
23324ae1
FM
497
498 /**
0b70c946 499 Return the long form of the path (returns identity on non-Windows platforms).
23324ae1 500 */
328f5751 501 wxString GetLongPath() const;
23324ae1
FM
502
503 /**
504 Returns the last time the file was last modified.
505 */
328f5751 506 wxDateTime GetModificationTime() const;
23324ae1
FM
507
508 /**
509 Returns the name part of the filename (without extension).
3c4f71cc 510
4cc4bfaf 511 @see GetFullName()
23324ae1 512 */
328f5751 513 wxString GetName() const;
23324ae1
FM
514
515 /**
35c2aa4f
VZ
516 Returns the path part of the filename (without the name or extension).
517
518 The possible flags values are:
3c4f71cc 519
0b70c946 520 - @b wxPATH_GET_VOLUME
35c2aa4f
VZ
521 Return the path with the volume (does nothing for the filename formats
522 without volumes), otherwise the path without volume part is returned.
3c4f71cc 523
0b70c946 524 - @b wxPATH_GET_SEPARATOR:
35c2aa4f
VZ
525 Return the path with the trailing separator, if this flag is not given
526 there will be no separator at the end of the path.
527
0b70c946 528 - @b wxPATH_NO_SEPARATOR:
35c2aa4f
VZ
529 Don't include the trailing separator in the returned string. This is
530 the default (the value of this flag is 0) and exists only for symmetry
531 with wxPATH_GET_SEPARATOR.
23324ae1
FM
532 */
533 wxString GetPath(int flags = wxPATH_GET_VOLUME,
328f5751 534 wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
535
536 /**
0b70c946
FM
537 Returns the usually used path separator for this format.
538 For all formats but @c wxPATH_DOS there is only one path separator anyhow,
539 but for DOS there are two of them and the native one, i.e. the backslash
540 is returned by this method.
3c4f71cc 541
4cc4bfaf 542 @see GetPathSeparators()
23324ae1
FM
543 */
544 static wxChar GetPathSeparator(wxPathFormat format = wxPATH_NATIVE);
545
546 /**
0b70c946
FM
547 Returns the string containing all the path separators for this format.
548 For all formats but @c wxPATH_DOS this string contains only one character
549 but for DOS and Windows both @c '/' and @c '\' may be used as separators.
3c4f71cc 550
4cc4bfaf 551 @see GetPathSeparator()
23324ae1
FM
552 */
553 static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE);
554
555 /**
0b70c946
FM
556 Returns the string of characters which may terminate the path part.
557 This is the same as GetPathSeparators() except for VMS
23324ae1
FM
558 path format where ] is used at the end of the path part.
559 */
560 static wxString GetPathTerminators(wxPathFormat format = wxPATH_NATIVE);
561
562 /**
0b70c946
FM
563 Returns the path with the trailing separator, useful for appending the name
564 to the given path.
565
566 This is the same as calling
567 @code
568 GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format)
569 @endcode
23324ae1 570 */
328f5751 571 wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
572
573 /**
574 Return the short form of the path (returns identity on non-Windows platforms).
575 */
328f5751 576 wxString GetShortPath() const;
23324ae1 577
23324ae1 578 /**
ca4bcd88
RR
579 Returns the size of the file If the file does not exist or its size could
580 not be read (because e.g. the file is locked by another process) the returned
0b70c946 581 value is ::wxInvalidSize.
23324ae1 582 */
adaaa686 583 wxULongLong GetSize() const;
0b70c946 584
ca4bcd88
RR
585 /**
586 Returns the size of the file If the file does not exist or its size could
587 not be read (because e.g. the file is locked by another process) the returned
0b70c946 588 value is ::wxInvalidSize.
ca4bcd88 589 */
328f5751 590 const static wxULongLong GetSize(const wxString& filename);
23324ae1
FM
591
592 /**
593 Returns the directory used for temporary files.
594 */
595 static wxString GetTempDir();
596
597 /**
0b70c946
FM
598 Returns the last access, last modification and creation times.
599 The last access time is updated whenever the file is read or written
600 (or executed in the case of Windows), last modification time is only
601 changed when the file is written to.
602 Finally, the creation time is indeed the time when the file was created
23324ae1
FM
603 under Windows and the inode change time under Unix (as it is impossible to
604 retrieve the real file creation time there anyhow) which can also be changed
605 by many operations after the file creation.
0b70c946 606
23324ae1 607 If no filename or extension is specified in this instance of wxFileName
0b70c946
FM
608 (and therefore IsDir() returns @true) then this function will return the
609 directory times of the path specified by GetPath(), otherwise the file
610 times of the file specified by GetFullPath().
611 Any of the pointers may be @NULL if the corresponding time is not needed.
3c4f71cc 612
d29a9a8a 613 @return @true on success, @false if we failed to retrieve the times.
23324ae1
FM
614 */
615 bool GetTimes(wxDateTime* dtAccess, wxDateTime* dtMod,
328f5751 616 wxDateTime* dtCreate) const;
23324ae1
FM
617
618 /**
619 Returns the string containing the volume for this file name, empty if it
0b70c946
FM
620 doesn't have one or if the file system doesn't support volumes at all
621 (for example, Unix).
23324ae1 622 */
328f5751 623 wxString GetVolume() const;
23324ae1
FM
624
625 /**
626 Returns the string separating the volume from the path for this format.
627 */
628 static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE);
629
35c2aa4f
VZ
630 /**
631 This function builds a volume path string, for example "C:\\".
632
633 Implemented for the platforms which use drive letters, i.e. DOS, MSW
634 and OS/2 only.
635
636 @since 2.9.0
637
638 @param drive
0b70c946 639 The drive letter, 'A' through 'Z' or 'a' through 'z'.
35c2aa4f
VZ
640
641 @param flags
0b70c946
FM
642 @c wxPATH_NO_SEPARATOR or @c wxPATH_GET_SEPARATOR to omit or include
643 the trailing path separator, the default is to include it.
35c2aa4f
VZ
644
645 @return Volume path string.
646 */
647 static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);
648
23324ae1
FM
649 /**
650 Returns @true if an extension is present.
651 */
328f5751 652 bool HasExt() const;
23324ae1
FM
653
654 /**
655 Returns @true if a name is present.
656 */
328f5751 657 bool HasName() const;
23324ae1
FM
658
659 /**
660 Returns @true if a volume specifier is present.
661 */
328f5751 662 bool HasVolume() const;
23324ae1
FM
663
664 /**
665 Inserts a directory component before the zero-based position in the directory
666 list. Please see AppendDir() for important notes.
667 */
668 void InsertDir(size_t before, const wxString& dir);
669
670 /**
671 Returns @true if this filename is absolute.
672 */
2bd56258 673 bool IsAbsolute(wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
674
675 /**
676 Returns @true if the file names of this type are case-sensitive.
677 */
678 static bool IsCaseSensitive(wxPathFormat format = wxPATH_NATIVE);
679
680 /**
681 Returns @true if this object represents a directory, @false otherwise
0b70c946
FM
682 (i.e. if it is a file).
683
684 Note that this method doesn't test whether the directory or file really
685 exists, you should use DirExists() or FileExists() for this.
23324ae1 686 */
328f5751 687 bool IsDir() const;
23324ae1 688
23324ae1 689 /**
2bd56258
RR
690 Returns @true if the directory component of this instance is an existing
691 directory and this process has read permissions on it. Read permissions
692 on a directory mean that you can list the directory contents but it
23324ae1
FM
693 doesn't imply that you have read permissions on the files contained.
694 */
2bd56258 695 bool IsDirReadable() const;
0b70c946 696
2bd56258
RR
697 /**
698 Returns @true if the given @e dir is an existing directory and this process
699 has read permissions on it. Read permissions on a directory mean that you
700 can list the directory contents but it doesn't imply that you have read
701 permissions on the files contained.
702 */
703 static bool IsDirReadable(const wxString& dir);
23324ae1 704
23324ae1 705 /**
2bd56258 706 Returns @true if the directory component of this instance
23324ae1
FM
707 is an existing directory and this process has write permissions on it.
708 Write permissions on a directory mean that you can create new files in the
709 directory.
710 */
2bd56258 711 bool IsDirWritable() const;
0b70c946 712
2bd56258 713 /**
0b70c946
FM
714 Returns @true if the given @a dir is an existing directory and this
715 process has write permissions on it.
2bd56258
RR
716 Write permissions on a directory mean that you can create new files in the
717 directory.
718 */
719 static bool IsDirWritable(const wxString& dir);
23324ae1 720
23324ae1
FM
721 /**
722 Returns @true if a file with this name exists and if this process has execute
723 permissions on it.
724 */
2bd56258 725 bool IsFileExecutable() const;
0b70c946 726
2bd56258
RR
727 /**
728 Returns @true if a file with this name exists and if this process has execute
729 permissions on it.
730 */
731 static bool IsFileExecutable(const wxString& file);
23324ae1 732
23324ae1
FM
733 /**
734 Returns @true if a file with this name exists and if this process has read
735 permissions on it.
736 */
2bd56258 737 bool IsFileReadable() const;
0b70c946 738
2bd56258
RR
739 /**
740 Returns @true if a file with this name exists and if this process has read
741 permissions on it.
742 */
743 static bool IsFileReadable(const wxString& file);
23324ae1 744
23324ae1
FM
745 /**
746 Returns @true if a file with this name exists and if this process has write
747 permissions on it.
748 */
2bd56258 749 bool IsFileWritable() const;
0b70c946 750
2bd56258
RR
751 /**
752 Returns @true if a file with this name exists and if this process has write
753 permissions on it.
754 */
755 static bool IsFileWritable(const wxString& file);
23324ae1
FM
756
757 /**
0b70c946
FM
758 Returns @true if the filename is valid, @false if it is not initialized yet.
759 The assignment functions and Clear() may reset the object to the uninitialized,
23324ae1
FM
760 invalid state (the former only do it on failure).
761 */
328f5751 762 bool IsOk() const;
23324ae1
FM
763
764 /**
765 Returns @true if the char is a path separator for this format.
766 */
767 static bool IsPathSeparator(wxChar ch,
768 wxPathFormat format = wxPATH_NATIVE);
769
770 /**
771 Returns @true if this filename is not absolute.
772 */
2bd56258 773 bool IsRelative(wxPathFormat format = wxPATH_NATIVE) const;
23324ae1
FM
774
775 /**
776 On Mac OS, gets the common type and creator for the given extension.
777 */
778 static bool MacFindDefaultTypeAndCreator(const wxString& ext,
0b70c946
FM
779 wxUint32* type,
780 wxUint32* creator);
23324ae1
FM
781
782 /**
0b70c946
FM
783 On Mac OS, registers application defined extensions and their default type
784 and creator.
23324ae1
FM
785 */
786 static void MacRegisterDefaultTypeAndCreator(const wxString& ext,
0b70c946
FM
787 wxUint32 type,
788 wxUint32 creator);
23324ae1
FM
789
790 /**
0b70c946
FM
791 On Mac OS, looks up the appropriate type and creator from the registration
792 and then sets it.
23324ae1
FM
793 */
794 bool MacSetDefaultTypeAndCreator();
795
796 /**
0b70c946
FM
797 Make the file name absolute.
798 This is a shortcut for
799 @code
800 wxFileName::Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE |
801 wxPATH_NORM_TILDE, cwd, format)
802 @endcode
3c4f71cc 803
4cc4bfaf 804 @see MakeRelativeTo(), Normalize(), IsAbsolute()
23324ae1
FM
805 */
806 bool MakeAbsolute(const wxString& cwd = wxEmptyString,
807 wxPathFormat format = wxPATH_NATIVE);
808
809 /**
7c913512 810 This function tries to put this file name in a form relative to
0b70c946
FM
811 @a pathBase.
812 In other words, it returns the file name which should be used to access
813 this file if the current directory were pathBase.
3c4f71cc 814
23324ae1 815 @param pathBase.
0b70c946 816 The directory to use as root, current directory is used by default
7c913512 817 @param format
0b70c946 818 The file name format, native by default
3c4f71cc 819
d29a9a8a 820 @return @true if the file name has been changed, @false if we failed to do
0b70c946
FM
821 anything with it (currently this only happens if the file name
822 is on a volume different from the volume specified by @a pathBase).
3c4f71cc 823
4cc4bfaf 824 @see Normalize()
23324ae1
FM
825 */
826 bool MakeRelativeTo(const wxString& pathBase = wxEmptyString,
827 wxPathFormat format = wxPATH_NATIVE);
828
23324ae1 829 /**
ca4bcd88 830 Creates a directory.
0b70c946
FM
831
832 @param perm
f41d6c8c 833 The permissions for the newly created directory.
b91c4601 834 See the ::wxPosixPermissions enumeration for more info.
ca4bcd88 835 @param flags
0b70c946
FM
836 If the flags contain @c wxPATH_MKDIR_FULL flag, try to create each
837 directory in the path and also don't return an error if the target
838 directory already exists.
ca4bcd88
RR
839
840 @return Returns @true if the directory was successfully created, @false
0b70c946 841 otherwise.
ca4bcd88 842 */
f41d6c8c 843 bool Mkdir(int perm = wxS_DIR_DEFAULT, int flags = 0);
0b70c946 844
ca4bcd88
RR
845 /**
846 Creates a directory.
0b70c946 847
7c913512 848 @param dir
f41d6c8c 849 The directory to create
7c913512 850 @param parm
f41d6c8c 851 The permissions for the newly created directory.
b91c4601 852 See the ::wxPosixPermissions enumeration for more info.
7c913512 853 @param flags
f41d6c8c 854 If the flags contain @c wxPATH_MKDIR_FULL flag, try to create each
0b70c946
FM
855 directory in the path and also don't return an error if the target
856 directory already exists.
3c4f71cc 857
d29a9a8a 858 @return Returns @true if the directory was successfully created, @false
0b70c946 859 otherwise.
23324ae1 860 */
f41d6c8c 861 static bool Mkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT,
7c913512 862 int flags = 0);
23324ae1
FM
863
864 /**
865 Normalize the path. With the default flags value, the path will be
866 made absolute, without any ".." and "." and all environment
867 variables will be expanded in it.
3c4f71cc 868
7c913512 869 @param flags
4cc4bfaf 870 The kind of normalization to do with the file name. It can be
0b70c946 871 any or-combination of the wxPathNormalize enumeration values.
4cc4bfaf
FM
872 @param cwd
873 If not empty, this directory will be used instead of current
0b70c946 874 working directory in normalization (see @c wxPATH_NORM_ABSOLUTE).
7c913512 875 @param format
4cc4bfaf 876 The file name format to use when processing the paths, native by default.
3c4f71cc 877
d29a9a8a 878 @return @true if normalization was successfully or @false otherwise.
23324ae1
FM
879 */
880 bool Normalize(int flags = wxPATH_NORM_ALL,
881 const wxString& cwd = wxEmptyString,
882 wxPathFormat format = wxPATH_NATIVE);
883
23324ae1 884 /**
0b70c946
FM
885 Prepends a directory to the file path.
886 Please see AppendDir() for important notes.
23324ae1
FM
887 */
888 void PrependDir(const wxString& dir);
889
890 /**
891 Removes the specified directory component from the path.
3c4f71cc 892
4cc4bfaf 893 @see GetDirCount()
23324ae1
FM
894 */
895 void RemoveDir(size_t pos);
896
897 /**
898 Removes last directory component from the path.
899 */
900 void RemoveLastDir();
901
23324ae1
FM
902 /**
903 Deletes the specified directory from the file system.
904 */
905 bool Rmdir();
0b70c946 906
2bd56258
RR
907 /**
908 Deletes the specified directory from the file system.
909 */
7c913512 910 static bool Rmdir(const wxString& dir);
23324ae1
FM
911
912 /**
913 Compares the filename using the rules of this platform.
914 */
915 bool SameAs(const wxFileName& filepath,
328f5751 916 wxPathFormat format = wxPATH_NATIVE) const;
23324ae1 917
23324ae1
FM
918 /**
919 Changes the current working directory.
920 */
921 bool SetCwd();
0b70c946 922
2bd56258
RR
923 /**
924 Changes the current working directory.
925 */
7c913512 926 static bool SetCwd(const wxString& cwd);
23324ae1
FM
927
928 /**
7c913512
FM
929 Sets the extension of the file name to be an empty extension.
930 This is different from having no extension at all as the file
23324ae1 931 name will have a trailing dot after a call to this method.
3c4f71cc 932
4cc4bfaf 933 @see SetExt(), ClearExt()
23324ae1
FM
934 */
935 void SetEmptyExt();
936
937 /**
0b70c946
FM
938 Sets the extension of the file name.
939
940 Setting an empty string as the extension will remove the extension
941 resulting in a file name without a trailing dot, unlike a call to
23324ae1 942 SetEmptyExt().
3c4f71cc 943
4cc4bfaf 944 @see SetEmptyExt(), ClearExt()
23324ae1
FM
945 */
946 void SetExt(const wxString& ext);
947
948 /**
949 The full name is the file name and extension (but without the path).
950 */
951 void SetFullName(const wxString& fullname);
952
953 /**
954 Sets the name part (without extension).
3c4f71cc 955
4cc4bfaf 956 @see SetFullName()
23324ae1
FM
957 */
958 void SetName(const wxString& name);
959
960 /**
961 Sets the file creation and last access/modification times (any of the pointers
962 may be @NULL).
963 */
964 bool SetTimes(const wxDateTime* dtAccess,
965 const wxDateTime* dtMod,
966 const wxDateTime* dtCreate);
967
968 /**
969 Sets the volume specifier.
970 */
971 void SetVolume(const wxString& volume);
972
973 //@{
974 /**
975 This function splits a full file name into components: the volume (with the
976 first version) path (including the volume in the second version), the base name
0b70c946
FM
977 and the extension.
978
979 Any of the output parameters (@e volume, @e path, @a name or @e ext) may
980 be @NULL if you are not interested in the value of a particular component.
981 Also, @a fullpath may be empty on entry.
4cc4bfaf
FM
982 On return, @a path contains the file path (without the trailing separator),
983 @a name contains the file name and @a ext contains the file extension
23324ae1
FM
984 without leading dot. All three of them may be empty if the corresponding
985 component is. The old contents of the strings pointed to by these parameters
986 will be overwritten in any case (if the pointers are not @NULL).
0b70c946 987
cdbcf4c2 988 Note that for a filename "foo." the extension is present, as indicated by the
7c913512 989 trailing dot, but empty. If you need to cope with such cases, you should use
4cc4bfaf 990 @a hasExt instead of relying on testing whether @a ext is empty or not.
23324ae1
FM
991 */
992 static void SplitPath(const wxString& fullpath, wxString* volume,
993 wxString* path,
994 wxString* name,
995 wxString* ext,
4cc4bfaf 996 bool hasExt = NULL,
23324ae1 997 wxPathFormat format = wxPATH_NATIVE);
7c913512
FM
998 static void SplitPath(const wxString& fullpath,
999 wxString* volume,
1000 wxString* path,
1001 wxString* name,
1002 wxString* ext,
1003 wxPathFormat format = wxPATH_NATIVE);
1004 static void SplitPath(const wxString& fullpath,
1005 wxString* path,
1006 wxString* name,
1007 wxString* ext,
1008 wxPathFormat format = wxPATH_NATIVE);
23324ae1
FM
1009 //@}
1010
1011 /**
4cc4bfaf 1012 Splits the given @a fullpath into the volume part (which may be empty) and
23324ae1 1013 the pure path part, not containing any volume.
3c4f71cc 1014
4cc4bfaf 1015 @see SplitPath()
23324ae1
FM
1016 */
1017 static void SplitVolume(const wxString& fullpath,
1018 wxString* volume,
1019 wxString* path,
1020 wxPathFormat format = wxPATH_NATIVE);
1021
1022 /**
1023 Sets the access and modification times to the current moment.
1024 */
1025 bool Touch();
1026
23324ae1
FM
1027 /**
1028 Returns @true if the filenames are different. The string @e filenames
1029 is interpreted as a path in the native filename format.
1030 */
0b70c946
FM
1031 bool operator!=(const wxFileName& filename) const;
1032
2bd56258
RR
1033 /**
1034 Returns @true if the filenames are different. The string @e filenames
1035 is interpreted as a path in the native filename format.
1036 */
0b70c946 1037 bool operator!=(const wxString& filename) const;
23324ae1 1038
23324ae1 1039 /**
0b70c946
FM
1040 Returns @true if the filenames are equal. The string @e filenames is
1041 interpreted as a path in the native filename format.
2bd56258 1042 */
0b70c946 1043 bool operator==(const wxFileName& filename) const;
23324ae1 1044
23324ae1
FM
1045 /**
1046 Returns @true if the filenames are equal. The string @e filenames is
1047 interpreted as a path in the native filename format.
1048 */
0b70c946
FM
1049 bool operator==(const wxString& filename) const;
1050
2bd56258 1051 /**
0b70c946
FM
1052 Assigns the new value to this filename object.
1053 */
1054 wxFileName& operator=(const wxFileName& filename);
1055
1056 /**
1057 Assigns the new value to this filename object.
2bd56258 1058 */
0b70c946 1059 wxFileName& operator=(const wxString& filename);
23324ae1 1060};
e54c96f1 1061