1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFileName
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
11 The various values for the path format: this mainly affects the path
12 separator but also whether or not the path has the drive part
15 See wxFileName for more info.
19 wxPATH_NATIVE
= 0, //!< the path format for the current platform.
21 wxPATH_BEOS
= wxPATH_UNIX
,
24 wxPATH_WIN
= wxPATH_DOS
,
25 wxPATH_OS2
= wxPATH_DOS
,
28 wxPATH_MAX
//!< Not a valid value for specifying path format
32 Different conventions for human readable sizes.
34 @see wxFileName::GetHumanReadableSize().
41 wxSIZE_CONV_TRADITIONAL
,
43 /// 1024 bytes = 1KiB.
52 The kind of normalization to do with the file name: these values can be
53 or'd together to perform several operations at once.
54 See wxFileName::Normalize() for more info.
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,
64 wxPATH_NORM_DOTS
= 0x0002, //!< Squeeze all @c ".." and @c ".".
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).
71 //! A value indicating all normalization flags except for @c wxPATH_NORM_CASE.
72 wxPATH_NORM_ALL
= 0x00ff & ~wxPATH_NORM_CASE
76 Flags for wxFileName::Rmdir().
80 /// Delete the specified directory and its subdirectories if they are empty.
81 wxPATH_RMDIR_FULL
= 1,
84 Delete the specified directory and all the files and subdirectories in it
87 This flag is obviously @b dangerous and should be used with care and
88 after asking the user for confirmation.
90 wxPATH_RMDIR_RECURSIVE
= 2
94 Flags for wxFileName::Exists().
100 wxFILE_EXISTS_REGULAR
= 0x0001, //!< Check for existence of a regular file
101 wxFILE_EXISTS_DIR
= 0x0002, //!< Check for existence of a directory
102 wxFILE_EXISTS_SYMLINK
= 0x0004, //!< Check for existence of a symbolic link
103 wxFILE_EXISTS_DEVICE
= 0x0008, //!< Check for existence of a device
104 wxFILE_EXISTS_FIFO
= 0x0016, //!< Check for existence of a FIFO
105 wxFILE_EXISTS_SOCKET
= 0x0032, //!< Check for existence of a socket
106 wxFILE_EXISTS_ANY
= 0x0FFF, //!< Check for existence of anything
107 wxFILE_EXISTS_NO_FOLLOW
= 0x1000 //!< Don't dereference a contained symbolic link
111 The return value of wxFileName::GetSize() in case of error.
113 wxULongLong wxInvalidSize
;
119 wxFileName encapsulates a file name.
121 This class serves two purposes: first, it provides the functions to split the
122 file names into components and to recombine these components in the full file
123 name which can then be passed to the OS file functions
124 (and @ref group_funcmacro_file "wxWidgets functions" wrapping them).
125 Second, it includes the functions for working with the files itself. Note that
126 to change the file data you should use wxFile class instead.
127 wxFileName provides functions for working with the file attributes.
129 When working with directory names (i.e. without filename and extension)
130 make sure not to misuse the file name part of this class with the last
131 directory. Instead initialize the wxFileName instance like this:
134 wxFileName dirname( "C:\mydir", "" );
135 MyMethod( dirname.GetPath() );
138 The same can be done using the static method wxFileName::DirName():
141 wxFileName dirname = wxFileName::DirName( "C:\mydir" );
142 MyMethod( dirname.GetPath() );
145 Accordingly, methods dealing with directories or directory names like
146 wxFileName::IsDirReadable() use wxFileName::GetPath() whereas methods dealing
147 with file names like wxFileName::IsFileReadable() use wxFileName::GetFullPath().
149 If it is not known whether a string contains a directory name or a complete
150 file name (such as when interpreting user input) you need to use the static
151 function wxFileName::DirExists() (or its identical variants wxDir::Exists() and
152 wxDirExists()) and construct the wxFileName instance accordingly.
153 This will only work if the directory actually exists, of course:
157 // get input from user
160 if (wxDirExists(user_input))
161 fname.AssignDir( user_input );
163 fname.Assign( user_input );
166 Please note that many wxFileName methods accept the path format argument
167 which is by @c wxPATH_NATIVE by default meaning to use the path format
168 native for the current platform.
169 The path format affects the operation of wxFileName functions in several ways:
170 first and foremost, it defines the path separator character to use, but it
171 also affects other things such as whether the path has the drive part or not.
172 See wxPathFormat for more info.
175 @section filename_format File name format
177 wxFileName currently supports the file names in the Unix, DOS/Windows,
178 Mac OS and VMS formats. Although these formats are quite different,
179 wxFileName tries to treat them all in the same generic way.
180 It supposes that all file names consist of the following parts: the volume
181 (also known as drive under Windows or device under VMS), the path which is
182 a sequence of directory names separated by the path separators and the full
183 filename itself which, in turn, is composed from the base file name and the
184 extension. All of the individual components of the file name may be empty
185 and, for example, the volume name is always empty under Unix, but if they
186 are all empty simultaneously, the filename object is considered to be in an
187 invalid state and wxFileName::IsOk() returns false for it.
189 File names can be case-sensitive or not, the function wxFileName::IsCaseSensitive()
190 allows to determine this. The rules for determining whether the file name is
191 absolute or relative also depend on the file name format and the only portable way
192 to answer this question is to use wxFileName::IsAbsolute() or wxFileName::IsRelative()
195 Note that on Windows,"X:" refers to the current working directory on drive X.
196 Therefore, a wxFileName instance constructed from for example "X:dir/file.ext"
197 treats the portion beyond drive separator as being relative to that directory.
198 To ensure that the filename is absolute, you may use wxFileName::MakeAbsolute().
199 There is also an inverse function wxFileName::MakeRelativeTo() which undoes
200 what wxFileName::Normalize(wxPATH_NORM_DOTS) does.
201 Other functions returning information about the file format provided by this
202 class are wxFileName::GetVolumeSeparator(), wxFileName::IsPathSeparator().
205 @section filename_construction File name construction
207 You can initialize a wxFileName instance using one of the following functions:
209 @li wxFileName::wxFileName()
210 @li wxFileName::Assign()
211 @li wxFileName::AssignCwd()
212 @li wxFileName::AssignDir()
213 @li wxFileName::AssignHomeDir()
214 @li wxFileName::AssignTempFileName()
215 @li wxFileName::DirName()
216 @li wxFileName::FileName()
217 @li wxFileName::operator=()
220 @section filename_tests File name tests
222 Before doing other tests, you should use wxFileName::IsOk() to verify that
223 the filename is well defined. If it is, FileExists() can be used to test whether
224 a file with such name exists and wxFileName::DirExists() can be used to test
225 for directory existence.
226 File names should be compared using the wxFileName::SameAs() method or
227 wxFileName::operator==(). For testing basic access modes, you can use:
229 @li wxFileName::IsDirWritable()
230 @li wxFileName::IsDirReadable()
231 @li wxFileName::IsFileWritable()
232 @li wxFileName::IsFileReadable()
233 @li wxFileName::IsFileExecutable()
236 @section filename_components File name components
238 These functions allow to examine and modify the individual directories
241 @li wxFileName::AppendDir()
242 @li wxFileName::InsertDir()
243 @li wxFileName::GetDirCount()
244 @li wxFileName::PrependDir()
245 @li wxFileName::RemoveDir()
246 @li wxFileName::RemoveLastDir()
248 To change the components of the file name individually you can use the
251 @li wxFileName::GetExt()
252 @li wxFileName::GetName()
253 @li wxFileName::GetVolume()
254 @li wxFileName::HasExt()
255 @li wxFileName::HasName()
256 @li wxFileName::HasVolume()
257 @li wxFileName::SetExt()
258 @li wxFileName::ClearExt()
259 @li wxFileName::SetEmptyExt()
260 @li wxFileName::SetName()
261 @li wxFileName::SetVolume()
263 You can initialize a wxFileName instance using one of the following functions:
266 @section filename_operations File name operations
268 These methods allow to work with the file creation, access and modification
269 times. Note that not all filesystems under all platforms implement these times
270 in the same way. For example, the access time under Windows has a resolution of
271 one day (so it is really the access date and not time). The access time may be
272 updated when the file is executed or not depending on the platform.
274 @li wxFileName::GetModificationTime()
275 @li wxFileName::GetTimes()
276 @li wxFileName::SetTimes()
277 @li wxFileName::Touch()
279 Other file system operations functions are:
281 @li wxFileName::Mkdir()
282 @li wxFileName::Rmdir()
299 wxFileName(const wxFileName
& filename
);
302 Constructor taking a full filename.
304 If it terminates with a '/', a directory path is constructed
305 (the name will be empty), otherwise a file name and extension
306 are extracted from it.
308 wxFileName(const wxString
& fullpath
,
309 wxPathFormat format
= wxPATH_NATIVE
);
312 Constructor a directory name and file name.
314 wxFileName(const wxString
& path
, const wxString
& name
,
315 wxPathFormat format
= wxPATH_NATIVE
);
318 Constructor from a directory name, base file name and extension.
320 wxFileName(const wxString
& path
, const wxString
& name
,
322 wxPathFormat format
= wxPATH_NATIVE
);
325 Constructor from a volume name, a directory name, base file name and extension.
327 wxFileName(const wxString
& volume
, const wxString
& path
,
328 const wxString
& name
,
330 wxPathFormat format
= wxPATH_NATIVE
);
333 Appends a directory component to the path. This component should contain a
334 single directory name level, i.e. not contain any path or volume separators nor
335 should it be empty, otherwise the function does nothing (and generates an
336 assert failure in debug build).
338 void AppendDir(const wxString
& dir
);
341 Creates the file name from another filename object.
343 void Assign(const wxFileName
& filepath
);
346 Creates the file name from a full file name with a path.
348 void Assign(const wxString
& fullpath
,
349 wxPathFormat format
= wxPATH_NATIVE
);
352 Creates the file name from volume, path, name and extension.
354 void Assign(const wxString
& volume
, const wxString
& path
,
355 const wxString
& name
,
358 wxPathFormat format
= wxPATH_NATIVE
);
361 Creates the file name from volume, path, name and extension.
363 void Assign(const wxString
& volume
, const wxString
& path
,
364 const wxString
& name
,
366 wxPathFormat format
= wxPATH_NATIVE
);
369 Creates the file name from file path and file name.
371 void Assign(const wxString
& path
, const wxString
& name
,
372 wxPathFormat format
= wxPATH_NATIVE
);
375 Creates the file name from path, name and extension.
377 void Assign(const wxString
& path
, const wxString
& name
,
379 wxPathFormat format
= wxPATH_NATIVE
);
382 Makes this object refer to the current working directory on the specified
383 volume (or current volume if @a volume is empty).
387 void AssignCwd(const wxString
& volume
= wxEmptyString
);
390 Sets this file name object to the given directory name.
391 The name and extension will be empty.
393 void AssignDir(const wxString
& dir
,
394 wxPathFormat format
= wxPATH_NATIVE
);
397 Sets this file name object to the home directory.
399 void AssignHomeDir();
402 The function calls CreateTempFileName() to create a temporary file
403 and sets this object to the name of the file.
405 If a temporary file couldn't be created, the object is put into
406 an invalid state (see IsOk()).
408 void AssignTempFileName(const wxString
& prefix
);
411 The function calls CreateTempFileName() to create a temporary
412 file name and open @a fileTemp with it.
414 If the file couldn't be opened, the object is put into
415 an invalid state (see IsOk()).
417 void AssignTempFileName(const wxString
& prefix
, wxFile
* fileTemp
);
420 The function calls CreateTempFileName() to create a temporary
421 file name and open @a fileTemp with it.
423 If the file couldn't be opened, the object is put into
424 an invalid state (see IsOk()).
426 void AssignTempFileName(const wxString
& prefix
, wxFFile
* fileTemp
);
429 Reset all components to default, uninitialized state.
434 Removes the extension from the file name resulting in a
435 file name with no trailing dot.
437 @see SetExt(), SetEmptyExt()
443 Returns a temporary file name starting with the given @e prefix.
444 If @a prefix is an absolute path and ends in a separator, the
445 temporary file is created in this directory; if it is an absolute
446 filepath or there is no separator, the temporary file is created in its
447 path, with the 'name' segment prepended to the temporary filename;
448 otherwise it is created in the default system directory for temporary
449 files or in the current directory.
451 If the function succeeds, the temporary file is actually created.
452 If @a fileTemp is not @NULL, this wxFile will be opened using the name of
453 the temporary file. Where possible this is done in an atomic way to ensure that
454 no race condition occurs between creating the temporary file name and opening
455 it, which might lead to a security compromise on multiuser systems.
456 If @a fileTemp is @NULL, the file is created but not opened.
457 Under Unix, the temporary file will have read and write permissions for the
458 owner only, to minimize security problems.
461 Location to use for the temporary file name construction. If @a prefix
462 is a directory it must have a terminal separator
464 The file to open, or @NULL just to get the name
466 @return The full temporary filepath, or an empty string on error.
468 static wxString
CreateTempFileName(const wxString
& prefix
,
469 wxFile
* fileTemp
= NULL
);
472 This is the same as CreateTempFileName(const wxString &prefix, wxFile *fileTemp)
473 but takes a wxFFile parameter instead of wxFile.
475 static wxString
CreateTempFileName(const wxString
& prefix
,
476 wxFFile
* fileTemp
= NULL
);
480 Returns @true if the directory with this name exists.
482 Notice that this function tests the directory part of this object,
483 i.e. the string returned by GetPath(), and not the full path returned
486 @see FileExists(), Exists()
488 bool DirExists() const;
491 Returns @true if the directory with name @a dir exists.
493 @see FileExists(), Exists()
495 static bool DirExists(const wxString
& dir
);
498 Returns the object corresponding to the directory with the given name.
499 The @a dir parameter may have trailing path separator or not.
501 static wxFileName
DirName(const wxString
& dir
,
502 wxPathFormat format
= wxPATH_NATIVE
);
505 Turns off symlink dereferencing.
507 By default, all operations in this class work on the target of a
508 symbolic link (symlink) if the path of the file is actually a symlink.
509 Using this method allows to turn off this "symlink following" behaviour
510 and apply the operations to this path itself, even if it is a symlink.
512 The following methods are currently affected by this option:
513 - GetTimes() (but not SetTimes() as there is no portable way to
514 change the time of symlink itself).
515 - Existence checks: FileExists(), DirExists() and Exists() (notice
516 that static versions of these methods always follow symlinks).
519 @see ShouldFollowLink()
523 void DontFollowLink();
526 Calls the static overload of this function with the full path of this
529 @since 2.9.4 (@a flags is new since 2.9.5)
531 bool Exists(int flags
= wxFILE_EXISTS_ANY
) const;
534 Returns @true if either a file or a directory or something else with
535 this name exists in the file system.
537 Don't dereference @a path if it is a symbolic link and @a flags
538 argument contains ::wxFILE_EXISTS_NO_FOLLOW.
540 This method is equivalent to @code FileExists() || DirExists() @endcode
541 under Windows, but under Unix it also returns true if the file
542 identifies a special file system object such as a device, a socket or a
545 Alternatively you may check for the existence of a file system entry of
546 a specific type by passing the appropriate @a flags (this parameter is
547 new since wxWidgets 2.9.5). E.g. to test for a symbolic link existence
548 you could use ::wxFILE_EXISTS_SYMLINK.
552 @see FileExists(), DirExists()
554 static bool Exists(const wxString
& path
, int flags
= wxFILE_EXISTS_ANY
);
557 Returns @true if the file with this name exists.
559 @see DirExists(), Exists()
561 bool FileExists() const;
564 Returns @true if the file with name @a file exists.
566 @see DirExists(), Exists()
568 static bool FileExists(const wxString
& file
);
571 Returns the file name object corresponding to the given @e file. This
572 function exists mainly for symmetry with DirName().
574 static wxFileName
FileName(const wxString
& file
,
575 wxPathFormat format
= wxPATH_NATIVE
);
578 Retrieves the value of the current working directory on the specified volume.
579 If the volume is empty, the program's current working directory is returned for
582 @return The string containing the current working directory or an empty
587 static wxString
GetCwd(const wxString
& volume
= wxEmptyString
);
590 Returns the number of directories in the file name.
592 size_t GetDirCount() const;
595 Returns the directories in string array form.
597 const wxArrayString
& GetDirs() const;
600 Returns the file name extension.
602 wxString
GetExt() const;
605 Returns the characters that can't be used in filenames and directory names
606 for the specified format.
608 static wxString
GetForbiddenChars(wxPathFormat format
= wxPATH_NATIVE
);
611 Returns the canonical path format for this platform.
613 static wxPathFormat
GetFormat(wxPathFormat format
= wxPATH_NATIVE
);
616 Returns the full name (including extension but excluding directories).
618 wxString
GetFullName() const;
621 Returns the full path with name and extension.
623 wxString
GetFullPath(wxPathFormat format
= wxPATH_NATIVE
) const;
626 Returns the home directory.
628 static wxString
GetHomeDir();
632 Returns the representation of the file size in a human-readable form.
634 In the first version, the size of this file is used. In the second one,
635 the specified size @a bytes is used.
637 If the file size could not be retrieved or @a bytes is ::wxInvalidSize
638 or zero, the @c failmsg string is returned.
640 Otherwise the returned string is a floating-point number with @c
641 precision decimal digits followed by the abbreviation of the unit used.
642 By default the traditional, although incorrect, convention of using SI
643 units for multiples of 1024 is used, i.e. returned string will use
644 suffixes of B, KB, MB, GB, TB for bytes, kilobytes, megabytes,
645 gigabytes and terabytes respectively. With the IEC convention the names
646 of the units are changed to B, KiB, MiB, GiB and TiB for bytes,
647 kibibytes, mebibytes, gibibytes and tebibytes. Finally, with SI
648 convention the same B, KB, MB, GB and TB suffixes are used but in their
649 correct SI meaning, i.e. as multiples of 1000 and not 1024.
651 Support for the different size conventions is new in wxWidgets 2.9.1,
652 in previous versions only the traditional convention was implemented.
655 GetHumanReadableSize(const wxString
& failmsg
= _("Not available"),
657 wxSizeConvention conv
= wxSIZE_CONV_TRADITIONAL
) const;
660 GetHumanReadableSize(const wxULongLong
& bytes
,
661 const wxString
& nullsize
= _("Not available"),
663 wxSizeConvention conv
= wxSIZE_CONV_TRADITIONAL
);
667 Return the long form of the path (returns identity on non-Windows platforms).
669 wxString
GetLongPath() const;
672 Returns the last time the file was last modified.
674 wxDateTime
GetModificationTime() const;
677 Returns the name part of the filename (without extension).
681 wxString
GetName() const;
684 Returns the path part of the filename (without the name or extension).
686 The possible flags values are:
688 - @b wxPATH_GET_VOLUME:
689 Return the path with the volume (does nothing for the filename formats
690 without volumes), otherwise the path without volume part is returned.
692 - @b wxPATH_GET_SEPARATOR:
693 Return the path with the trailing separator, if this flag is not given
694 there will be no separator at the end of the path.
696 - @b wxPATH_NO_SEPARATOR:
697 Don't include the trailing separator in the returned string. This is
698 the default (the value of this flag is 0) and exists only for symmetry
699 with wxPATH_GET_SEPARATOR.
701 @note If the path is a toplevel one (e.g. @c "/" on Unix or @c "C:\" on
702 Windows), then the returned path will contain trailing separator
703 even with @c wxPATH_NO_SEPARATOR.
705 wxString
GetPath(int flags
= wxPATH_GET_VOLUME
,
706 wxPathFormat format
= wxPATH_NATIVE
) const;
709 Returns the usually used path separator for this format.
710 For all formats but @c wxPATH_DOS there is only one path separator anyhow,
711 but for DOS there are two of them and the native one, i.e. the backslash
712 is returned by this method.
714 @see GetPathSeparators()
716 static wxUniChar
GetPathSeparator(wxPathFormat format
= wxPATH_NATIVE
);
719 Returns the string containing all the path separators for this format.
720 For all formats but @c wxPATH_DOS this string contains only one character
721 but for DOS and Windows both @c '/' and @c '\' may be used as separators.
723 @see GetPathSeparator()
725 static wxString
GetPathSeparators(wxPathFormat format
= wxPATH_NATIVE
);
728 Returns the string of characters which may terminate the path part.
729 This is the same as GetPathSeparators() except for VMS
730 path format where ] is used at the end of the path part.
732 static wxString
GetPathTerminators(wxPathFormat format
= wxPATH_NATIVE
);
735 Returns the path with the trailing separator, useful for appending the name
738 This is the same as calling
740 GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format)
743 wxString
GetPathWithSep(wxPathFormat format
= wxPATH_NATIVE
) const;
746 Return the short form of the path (returns identity on non-Windows platforms).
748 wxString
GetShortPath() const;
751 Returns the size of the file If the file does not exist or its size could
752 not be read (because e.g. the file is locked by another process) the returned
753 value is ::wxInvalidSize.
755 wxULongLong
GetSize() const;
758 Returns the size of the file If the file does not exist or its size could
759 not be read (because e.g. the file is locked by another process) the returned
760 value is ::wxInvalidSize.
762 static wxULongLong
GetSize(const wxString
& filename
);
765 Returns the directory used for temporary files.
767 static wxString
GetTempDir();
770 Returns the last access, last modification and creation times.
771 The last access time is updated whenever the file is read or written
772 (or executed in the case of Windows), last modification time is only
773 changed when the file is written to.
774 Finally, the creation time is indeed the time when the file was created
775 under Windows and the inode change time under Unix (as it is impossible to
776 retrieve the real file creation time there anyhow) which can also be changed
777 by many operations after the file creation.
779 If no filename or extension is specified in this instance of wxFileName
780 (and therefore IsDir() returns @true) then this function will return the
781 directory times of the path specified by GetPath(), otherwise the file
782 times of the file specified by GetFullPath().
783 Any of the pointers may be @NULL if the corresponding time is not needed.
785 @return @true on success, @false if we failed to retrieve the times.
787 bool GetTimes(wxDateTime
* dtAccess
, wxDateTime
* dtMod
,
788 wxDateTime
* dtCreate
) const;
791 Returns the string containing the volume for this file name, empty if it
792 doesn't have one or if the file system doesn't support volumes at all
795 wxString
GetVolume() const;
798 Returns the string separating the volume from the path for this format.
800 static wxString
GetVolumeSeparator(wxPathFormat format
= wxPATH_NATIVE
);
803 This function builds a volume path string, for example "C:\\".
805 Implemented for the platforms which use drive letters, i.e. DOS, MSW
811 The drive letter, 'A' through 'Z' or 'a' through 'z'.
814 @c wxPATH_NO_SEPARATOR or @c wxPATH_GET_SEPARATOR to omit or include
815 the trailing path separator, the default is to include it.
817 @return Volume path string.
819 static wxString
GetVolumeString(char drive
, int flags
= wxPATH_GET_SEPARATOR
);
822 Returns @true if an extension is present.
827 Returns @true if a name is present.
829 bool HasName() const;
832 Returns @true if a volume specifier is present.
834 bool HasVolume() const;
837 Inserts a directory component before the zero-based position in the directory
838 list. Please see AppendDir() for important notes.
840 void InsertDir(size_t before
, const wxString
& dir
);
843 Returns @true if this filename is absolute.
845 bool IsAbsolute(wxPathFormat format
= wxPATH_NATIVE
) const;
848 Returns @true if the file names of this type are case-sensitive.
850 static bool IsCaseSensitive(wxPathFormat format
= wxPATH_NATIVE
);
853 Returns @true if this object represents a directory, @false otherwise
854 (i.e. if it is a file).
856 Note that this method doesn't test whether the directory or file really
857 exists, you should use DirExists() or FileExists() for this.
862 Returns @true if the directory component of this instance is an existing
863 directory and this process has read permissions on it. Read permissions
864 on a directory mean that you can list the directory contents but it
865 doesn't imply that you have read permissions on the files contained.
867 bool IsDirReadable() const;
870 Returns @true if the given @e dir is an existing directory and this process
871 has read permissions on it. Read permissions on a directory mean that you
872 can list the directory contents but it doesn't imply that you have read
873 permissions on the files contained.
875 static bool IsDirReadable(const wxString
& dir
);
878 Returns @true if the directory component of this instance
879 is an existing directory and this process has write permissions on it.
880 Write permissions on a directory mean that you can create new files in the
883 bool IsDirWritable() const;
886 Returns @true if the given @a dir is an existing directory and this
887 process has write permissions on it.
888 Write permissions on a directory mean that you can create new files in the
891 static bool IsDirWritable(const wxString
& dir
);
894 Returns @true if a file with this name exists and if this process has execute
897 bool IsFileExecutable() const;
900 Returns @true if a file with this name exists and if this process has execute
903 static bool IsFileExecutable(const wxString
& file
);
906 Returns @true if a file with this name exists and if this process has read
909 bool IsFileReadable() const;
912 Returns @true if a file with this name exists and if this process has read
915 static bool IsFileReadable(const wxString
& file
);
918 Returns @true if a file with this name exists and if this process has write
921 bool IsFileWritable() const;
924 Returns @true if a file with this name exists and if this process has write
927 static bool IsFileWritable(const wxString
& file
);
930 Returns @true if the filename is valid, @false if it is not initialized yet.
931 The assignment functions and Clear() may reset the object to the uninitialized,
932 invalid state (the former only do it on failure).
937 Returns @true if the char is a path separator for this format.
939 static bool IsPathSeparator(wxChar ch
,
940 wxPathFormat format
= wxPATH_NATIVE
);
943 Returns @true if the volume part of the path is a unique volume name.
945 This function will always return @false if the path format is not
948 Unique volume names are Windows volume identifiers which remain the same
949 regardless of where the volume is actually mounted. Example of a path
950 using a volume name could be
952 \\?\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\Program Files\setup.exe
957 static bool IsMSWUniqueVolumeNamePath(const wxString
& path
,
958 wxPathFormat format
= wxPATH_NATIVE
);
961 Returns @true if this filename is not absolute.
963 bool IsRelative(wxPathFormat format
= wxPATH_NATIVE
) const;
966 On Mac OS, gets the common type and creator for the given extension.
970 static bool MacFindDefaultTypeAndCreator(const wxString
& ext
,
975 On Mac OS, registers application defined extensions and their default type
980 static void MacRegisterDefaultTypeAndCreator(const wxString
& ext
,
985 On Mac OS, looks up the appropriate type and creator from the registration
990 bool MacSetDefaultTypeAndCreator();
993 Make the file name absolute.
994 This is a shortcut for
996 wxFileName::Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE |
997 wxPATH_NORM_TILDE, cwd, format)
1000 @see MakeRelativeTo(), Normalize(), IsAbsolute()
1002 bool MakeAbsolute(const wxString
& cwd
= wxEmptyString
,
1003 wxPathFormat format
= wxPATH_NATIVE
);
1006 This function tries to put this file name in a form relative to
1008 In other words, it returns the file name which should be used to access
1009 this file if the current directory were pathBase.
1012 The directory to use as root, current directory is used by default
1014 The file name format, native by default
1016 @return @true if the file name has been changed, @false if we failed to do
1017 anything with it (currently this only happens if the file name
1018 is on a volume different from the volume specified by @a pathBase).
1022 bool MakeRelativeTo(const wxString
& pathBase
= wxEmptyString
,
1023 wxPathFormat format
= wxPATH_NATIVE
);
1026 Creates a directory.
1029 The permissions for the newly created directory.
1030 See the ::wxPosixPermissions enumeration for more info.
1032 If the flags contain @c wxPATH_MKDIR_FULL flag, try to create each
1033 directory in the path and also don't return an error if the target
1034 directory already exists.
1036 @return Returns @true if the directory was successfully created, @false
1039 bool Mkdir(int perm
= wxS_DIR_DEFAULT
, int flags
= 0) const;
1042 Creates a directory.
1045 The directory to create
1047 The permissions for the newly created directory.
1048 See the ::wxPosixPermissions enumeration for more info.
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.
1054 @return Returns @true if the directory was successfully created, @false
1057 static bool Mkdir(const wxString
& dir
, int perm
= wxS_DIR_DEFAULT
,
1063 With the default flags value, the path will be made absolute, without
1064 any ".." and "." and all environment variables will be expanded in it.
1066 Notice that in some rare cases normalizing a valid path may result in
1067 an invalid wxFileName object. E.g. normalizing "./" path using
1068 wxPATH_NORM_DOTS but not wxPATH_NORM_ABSOLUTE will result in a
1069 completely empty and thus invalid object. As long as there is a non
1070 empty file name the result of normalization will be valid however.
1073 The kind of normalization to do with the file name. It can be
1074 any or-combination of the ::wxPathNormalize enumeration values.
1076 If not empty, this directory will be used instead of current
1077 working directory in normalization (see @c wxPATH_NORM_ABSOLUTE).
1079 The file name format to use when processing the paths, native by default.
1081 @return @true if normalization was successfully or @false otherwise.
1083 bool Normalize(int flags
= wxPATH_NORM_ALL
,
1084 const wxString
& cwd
= wxEmptyString
,
1085 wxPathFormat format
= wxPATH_NATIVE
);
1088 Prepends a directory to the file path.
1089 Please see AppendDir() for important notes.
1091 void PrependDir(const wxString
& dir
);
1094 Removes the specified directory component from the path.
1098 void RemoveDir(size_t pos
);
1101 Removes last directory component from the path.
1103 void RemoveLastDir();
1106 If the path contains the value of the environment variable named @a envname
1107 then this function replaces it with the string obtained from
1108 wxString::Format(replacementFmtString, value_of_envname_variable).
1110 This function is useful to make the path shorter or to make it dependent
1111 from a certain environment variable.
1112 Normalize() with @c wxPATH_NORM_ENV_VARS can perform the opposite of this
1113 function (depending on the value of @a replacementFmtString).
1115 The name and extension of this filename are not modified.
1119 wxFileName fn("/usr/openwin/lib/someFile");
1120 fn.ReplaceEnvVariable("OPENWINHOME");
1121 // now fn.GetFullPath() == "$OPENWINHOME/lib/someFile"
1126 @return @true if the operation was successful (which doesn't mean
1127 that something was actually replaced, just that ::wxGetEnv
1130 bool ReplaceEnvVariable(const wxString
& envname
,
1131 const wxString
& replacementFmtString
= "$%s",
1132 wxPathFormat format
= wxPATH_NATIVE
);
1135 Replaces, if present in the path, the home directory for the given user
1136 (see ::wxGetHomeDir) with a tilde (~).
1138 Normalize() with @c wxPATH_NORM_TILDE performs the opposite of this
1141 The name and extension of this filename are not modified.
1145 @return @true if the operation was successful (which doesn't mean
1146 that something was actually replaced, just that ::wxGetHomeDir
1149 bool ReplaceHomeDir(wxPathFormat format
= wxPATH_NATIVE
);
1153 Deletes the specified directory from the file system.
1156 Can contain one of wxPATH_RMDIR_FULL or wxPATH_RMDIR_RECURSIVE. By
1157 default contains neither so the directory will not be removed
1160 @return Returns @true if the directory was successfully deleted, @false
1163 bool Rmdir(int flags
= 0) const;
1166 Deletes the specified directory from the file system.
1169 The directory to delete
1171 Can contain one of wxPATH_RMDIR_FULL or wxPATH_RMDIR_RECURSIVE. By
1172 default contains neither so the directory will not be removed
1175 @return Returns @true if the directory was successfully deleted, @false
1178 static bool Rmdir(const wxString
& dir
, int flags
= 0);
1181 Compares the filename using the rules of this platform.
1183 bool SameAs(const wxFileName
& filepath
,
1184 wxPathFormat format
= wxPATH_NATIVE
) const;
1187 Changes the current working directory.
1189 bool SetCwd() const;
1192 Changes the current working directory.
1194 static bool SetCwd(const wxString
& cwd
);
1197 Sets the extension of the file name to be an empty extension.
1198 This is different from having no extension at all as the file
1199 name will have a trailing dot after a call to this method.
1201 @see SetExt(), ClearExt()
1206 Sets the extension of the file name.
1208 Setting an empty string as the extension will remove the extension
1209 resulting in a file name without a trailing dot, unlike a call to
1212 @see SetEmptyExt(), ClearExt()
1214 void SetExt(const wxString
& ext
);
1217 The full name is the file name and extension (but without the path).
1219 void SetFullName(const wxString
& fullname
);
1222 Sets the name part (without extension).
1226 void SetName(const wxString
& name
);
1231 The @a path argument includes both the path and the volume, if
1232 supported by @a format.
1234 Calling this function doesn't affect the name and extension components,
1235 to change them as well you can use Assign() or just an assignment
1240 void SetPath(const wxString
& path
, wxPathFormat format
= wxPATH_NATIVE
);
1243 Sets the file creation and last access/modification times (any of the pointers
1246 bool SetTimes(const wxDateTime
* dtAccess
,
1247 const wxDateTime
* dtMod
,
1248 const wxDateTime
* dtCreate
) const;
1251 Sets the volume specifier.
1253 void SetVolume(const wxString
& volume
);
1256 Return whether some operations will follow symlink.
1258 By default, file operations "follow symlink", i.e. operate on its
1259 target and not on the symlink itself. See DontFollowLink() for more
1264 bool ShouldFollowLink() const;
1268 This function splits a full file name into components: the volume (with the
1269 first version) path (including the volume in the second version), the base name
1272 Any of the output parameters (@e volume, @e path, @a name or @e ext) may
1273 be @NULL if you are not interested in the value of a particular component.
1274 Also, @a fullpath may be empty on entry.
1275 On return, @a path contains the file path (without the trailing separator),
1276 @a name contains the file name and @a ext contains the file extension
1277 without leading dot. All three of them may be empty if the corresponding
1278 component is. The old contents of the strings pointed to by these parameters
1279 will be overwritten in any case (if the pointers are not @NULL).
1281 Note that for a filename "foo." the extension is present, as indicated by the
1282 trailing dot, but empty. If you need to cope with such cases, you should use
1283 @a hasExt instead of relying on testing whether @a ext is empty or not.
1285 static void SplitPath(const wxString
& fullpath
,
1290 bool* hasExt
= NULL
,
1291 wxPathFormat format
= wxPATH_NATIVE
);
1292 static void SplitPath(const wxString
& fullpath
,
1297 wxPathFormat format
);
1298 static void SplitPath(const wxString
& fullpath
,
1302 wxPathFormat format
= wxPATH_NATIVE
);
1306 Splits the given @a fullpath into the volume part (which may be empty) and
1307 the pure path part, not containing any volume.
1311 static void SplitVolume(const wxString
& fullpath
,
1314 wxPathFormat format
= wxPATH_NATIVE
);
1318 Strip the file extension.
1320 This function does more than just removing everything after the last
1321 period from the string, for example it will return the string ".vimrc"
1322 unchanged because the part after the period is not an extension but the
1323 file name in this case. You can use wxString::BeforeLast() to really
1324 get just the part before the last period (but notice that that function
1325 returns empty string if period is not present at all unlike this
1326 function which returns the @a fullname unchanged in this case).
1329 File path including name and, optionally, extension.
1332 File path without extension
1336 static wxString
StripExtension(const wxString
& fullname
);
1339 Sets the access and modification times to the current moment.
1344 Returns @true if the filenames are different. The string @e filenames
1345 is interpreted as a path in the native filename format.
1347 bool operator!=(const wxFileName
& filename
) const;
1350 Returns @true if the filenames are different. The string @e filenames
1351 is interpreted as a path in the native filename format.
1353 bool operator!=(const wxString
& filename
) const;
1356 Returns @true if the filenames are equal. The string @e filenames is
1357 interpreted as a path in the native filename format.
1359 bool operator==(const wxFileName
& filename
) const;
1362 Returns @true if the filenames are equal. The string @e filenames is
1363 interpreted as a path in the native filename format.
1365 bool operator==(const wxString
& filename
) const;
1368 Assigns the new value to this filename object.
1370 wxFileName
& operator=(const wxFileName
& filename
);
1373 Assigns the new value to this filename object.
1375 wxFileName
& operator=(const wxString
& filename
);