1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxFileName documentation
4 %% Author: Vadim Zeitlin
8 %% Copyright: (c) 2001 Vadim Zeitlin
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxFileName
}}\label{wxfilename
}
14 wxFileName encapsulates a file name. This class serves two purposes: first, it
15 provides the functions to split the file names into components and to recombine
16 these components in the full file name which can then be passed to the OS file
17 functions (and
\helpref{wxWidgets functions
}{filefunctions
} wrapping them).
18 Second, it includes the functions for working with the files itself. Note that
19 to change the file data you should use
\helpref{wxFile
}{wxfile
} class instead.
20 wxFileName provides functions for working with the file attributes.
22 When working with directory names (i.e. without filename and extension)
23 make sure not to misuse the file name part of this class with the last
24 directory. Instead initialize the wxFileName instance like this:
27 wxFileName dirname( wxT("C:
\mydir"), wxEmptyString );
28 MyMethod( dirname.GetPath() );
31 Accordingly, methods dealing with directories or directory names
32 like
\helpref{IsDirReadable
}{wxfilenameisdirreadale
} use
33 \helpref{GetPath
}{wxfilenamegetpath
} whereas methods dealing
34 with file names like
\helpref{IsFileReadable
}{wxfilenameisfilereadale
}
35 use
\helpref{GetFullPath
}{wxfilenamegetfullpath
}.
37 If it is not known wether a string contains a directory name or
38 a complete file name (such as when interpreting user input) you need to use
39 the static function
\helpref{wxFileName::DirExists
}{wxfilenamedirexists
}
40 (or its global variant
\helpref{wxDirExists
}{wxdirexists
}) and
41 construct the wxFileName instance accordingly. This will only work
42 if the directory actually exists, of course:
46 // get input from user
49 if (wxDirExists(user_input))
50 fname.AssignDir( user_input );
52 fname.Assign( user_input );
55 \wxheading{Derived from
}
59 \wxheading{Include files
}
63 \wxheading{Data structures
}
65 Many wxFileName methods accept the path format argument which is by
\rtfsp
66 {\tt wxPATH
\_NATIVE} by default meaning to use the path format native for the
69 The path format affects the operation of wxFileName functions in several ways:
70 first and foremost, it defines the path separator character to use, but it also
71 affects other things such as whether the path has the drive part or not.
76 wxPATH_NATIVE =
0, // the path format for the current platform
78 wxPATH_BEOS = wxPATH_UNIX,
81 wxPATH_WIN = wxPATH_DOS,
82 wxPATH_OS2 = wxPATH_DOS,
85 wxPATH_MAX // Not a valid value for specifying path format
89 \latexignore{\rtfignore{\wxheading{Function groups
}}}
92 \membersection{File name format
}\label{filenameformat
}
94 wxFileName currently supports the file names in the Unix, DOS/Windows, Mac OS
95 and VMS formats. Although these formats are quite different, wxFileName tries
96 to treat them all in the same generic way. It supposes that all file names
97 consist of the following parts: the volume (also known as drive under Windows
98 or device under VMS), the path which is a sequence of directory names separated
99 by the
\helpref{path separators
}{wxfilenamegetpathseparators
} and the full
100 filename itself which, in turn, is composed from the base file name and the
101 extension. All of the individual components of the file name may be empty and,
102 for example, the volume name is always empty under Unix, but if they are all
103 empty simultaneously, the filename object is considered to be in an invalid
104 state and
\helpref{IsOk
}{wxfilenameisok
} returns
{\tt false
} for it.
106 File names can be case-sensitive or not, the function
\rtfsp
107 \helpref{IsCaseSensitive
}{wxfilenameiscasesensitive
} allows to determine this.
109 The rules for determining whether the file name is absolute or relative also
110 depend on the file name format and the only portable way to answer this
111 question is to use
\helpref{IsAbsolute
}{wxfilenameisabsolute
} or
\rtfsp
112 \helpref{IsRelative
}{wxfilenameisrelative
} method. Note that on Windows, "X:"
113 refers to the current working directory on drive X. Therefore, a wxFileName
114 instance constructed from for example "X:dir/file.ext" treats the portion
115 beyond drive separator as being relative to that directory.
117 To ensure that the filename is absolute, you may use
\rtfsp
118 \helpref{MakeAbsolute
}{wxfilenamemakeabsolute
}. There is also an inverse
119 function
\helpref{MakeRelativeTo
}{wxfilenamemakerelativeto
} which undoes
120 what
\helpref{Normalize(wxPATH
\_NORM\_DOTS)
}{wxfilenamenormalize
} does.
122 Other functions returning information about the file format provided by this
123 class are
\helpref{GetVolumeSeparator
}{wxfilenamegetvolumeseparator
},
\rtfsp
124 \helpref{IsPathSeparator
}{wxfilenameispathseparator
}.
127 \membersection{File name construction
}\label{filenameconstruction
}
129 You can initialize a wxFileName instance using one of the following functions:
131 \helpref{wxFileName constructors
}{wxfilenamewxfilename
}\\
132 \helpref{Assign
}{wxfilenameassign
}\\
133 \helpref{AssignCwd
}{wxfilenameassigncwd
}\\
134 \helpref{AssignDir
}{wxfilenameassigndir
}\\
135 \helpref{AssignHomeDir
}{wxfilenameassignhomedir
}\\
136 \helpref{AssignHomeTempFileName
}{wxfilenameassigntempfilename
}\\
137 \helpref{operator $=$
}{wxfilenameoperatorassign
}
140 \membersection{File tests
}\label{filetests
}
142 Before doing other tests, you should use
\helpref{IsOk
}{wxfilenameisok
} to
143 verify that the filename is well defined. If it is,
\rtfsp
144 \helpref{FileExists
}{wxfilenamefileexists
} can be used to test whether a file
145 with such name exists and
\helpref{DirExists
}{wxfilenamedirexists
} can be used
146 to test for directory existence.
148 File names should be compared using
\helpref{SameAs
}{wxfilenamesameas
} method
149 or
\helpref{operator $==$
}{wxfilenameoperatorequal
}.
151 For testing basic access modes, you can use:
153 \helpref{IsDirWritable
}{wxfilenameisdirwritable
}\\
154 \helpref{IsDirReadable
}{wxfilenameisdirreadable
}\\
155 \helpref{IsFileWritable
}{wxfilenameisfilewritable
}\\
156 \helpref{IsFileReadable
}{wxfilenameisfilereadable
}\\
157 \helpref{IsFileExecutable
}{wxfilenameisfileexecutable
}
160 \membersection{File name components
}\label{filenamecomponents
}
162 These functions allow to examine and modify the individual directories of the
165 \helpref{AppendDir
}{wxfilenameappenddir
}\\
166 \helpref{InsertDir
}{wxfilenameinsertdir
}\\
167 \helpref{GetDirCount
}{wxfilenamegetdircount
}
168 \helpref{PrependDir
}{wxfilenameprependdir
}\\
169 \helpref{RemoveDir
}{wxfilenameremovedir
}\\
170 \helpref{RemoveLastDir
}{wxfilenameremovelastdir
}
172 To change the components of the file name individually you can use the
175 \helpref{GetExt
}{wxfilenamegetext
}\\
176 \helpref{GetName
}{wxfilenamegetname
}\\
177 \helpref{GetVolume
}{wxfilenamegetvolume
}\\
178 \helpref{HasExt
}{wxfilenamehasext
}\\
179 \helpref{HasName
}{wxfilenamehasname
}\\
180 \helpref{HasVolume
}{wxfilenamehasvolume
}\\
181 \helpref{SetExt
}{wxfilenamesetext
}\\
182 \helpref{ClearExt
}{wxfilenameclearext
}\\
183 \helpref{SetEmptyExt
}{wxfilenamesetemptyext
}\\
184 \helpref{SetName
}{wxfilenamesetname
}\\
185 \helpref{SetVolume
}{wxfilenamesetvolume
}\\
188 \membersection{Operations
}\label{filenameoperations
}
190 These methods allow to work with the file creation, access and modification
191 times. Note that not all filesystems under all platforms implement these times
192 in the same way. For example, the access time under Windows has a resolution of
193 one day (so it is really the access date and not time). The access time may be
194 updated when the file is executed or not depending on the platform.
196 \helpref{GetModificationTime
}{wxfilenamegetmodificationtime
}\\
197 \helpref{GetTimes
}{wxfilenamegettimes
}\\
198 \helpref{SetTimes
}{wxfilenamesettimes
}\\
199 \helpref{Touch
}{wxfilenametouch
}
201 Other file system operations functions are:
203 \helpref{Mkdir
}{wxfilenamemkdir
}\\
204 \helpref{Rmdir
}{wxfilenamermdir
}
206 \latexignore{\rtfignore{\wxheading{Members
}}}
209 \membersection{wxFileName::wxFileName
}\label{wxfilenamewxfilename
}
211 \func{}{wxFileName
}{\void}
215 \func{}{wxFileName
}{\param{const wxFileName\&
}{filename
}}
219 \func{}{wxFileName
}{\param{const wxString\&
}{fullpath
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
221 Constructor taking a full filename. If it terminates with a '/', a directory path
222 is constructed (the name will be empty), otherwise a file name and
223 extension are extracted from it.
225 \func{}{wxFileName
}{\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
227 Constructor from a directory name and a file name.
229 \func{}{wxFileName
}{\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
231 Constructor from a directory name, base file name and extension.
233 \func{}{wxFileName
}{\param{const wxString\&
}{volume
},
\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
235 Constructor from a volume name, a directory name, base file name and extension.
238 \membersection{wxFileName::AppendDir
}\label{wxfilenameappenddir
}
240 \func{void
}{AppendDir
}{\param{const wxString\&
}{dir
}}
242 Appends a directory component to the path. This component should contain a
243 single directory name level, i.e. not contain any path or volume separators nor
244 should it be empty, otherwise the function does nothing (and generates an
245 assert failure in debug build).
248 \membersection{wxFileName::Assign
}\label{wxfilenameassign
}
250 \func{void
}{Assign
}{\param{const wxFileName\&
}{filepath
}}
252 \func{void
}{Assign
}{\param{const wxString\&
}{fullpath
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
254 \func{void
}{Assign
}{\param{const wxString\&
}{volume
},
\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{bool
}{hasExt
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
256 \func{void
}{Assign
}{\param{const wxString\&
}{volume
},
\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
258 \func{void
}{Assign
}{\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
260 \func{void
}{Assign
}{\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
262 Creates the file name from various combinations of data.
265 \membersection{wxFileName::AssignCwd
}\label{wxfilenameassigncwd
}
267 \func{static void
}{AssignCwd
}{\param{const wxString\&
}{volume = wxEmptyString
}}
269 Makes this object refer to the current working directory on the specified
270 volume (or current volume if
{\it volume
} is empty).
274 \helpref{GetCwd
}{wxfilenamegetcwd
}
277 \membersection{wxFileName::AssignDir
}\label{wxfilenameassigndir
}
279 \func{void
}{AssignDir
}{\param{const wxString\&
}{dir
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
281 Sets this file name object to the given directory name. The name and extension
285 \membersection{wxFileName::AssignHomeDir
}\label{wxfilenameassignhomedir
}
287 \func{void
}{AssignHomeDir
}{\void}
289 Sets this file name object to the home directory.
292 \membersection{wxFileName::AssignTempFileName
}\label{wxfilenameassigntempfilename
}
294 \func{void
}{AssignTempFileName
}{\param{const wxString\&
}{prefix
},
\param{wxFile *
}{fileTemp =
{\tt NULL
}}}
296 The function calls
\helpref{CreateTempFileName
}{wxfilenamecreatetempfilename
} to
297 create a temporary file and sets this object to the name of the file. If a
298 temporary file couldn't be created, the object is put into the
\rtfsp
299 \helpref{invalid
}{wxfilenameisok
} state.
302 \membersection{wxFileName::Clear
}\label{wxfilenameclear
}
304 \func{void
}{Clear
}{\void}
306 Reset all components to default, uninitialized state.
309 \membersection{wxFileName::ClearExt
}\label{wxfilenameclearext
}
311 \func{void
}{SetClearExt
}{\void}
313 Removes the extension from the file name resulting in a
314 file name with no trailing dot.
318 \helpref{SetExt
}{wxfilenamesetext
}
319 \helpref{SetEmptyExt
}{wxfilenamesetemptyext
}
321 \membersection{wxFileName::CreateTempFileName
}\label{wxfilenamecreatetempfilename
}
323 \func{static wxString
}{CreateTempFileName
}{\param{const wxString\&
}{prefix
},
\param{wxFile *
}{fileTemp =
{\tt NULL
}}}
325 Returns a temporary file name starting with the given
{\it prefix
}. If
326 the
{\it prefix
} is an absolute path, the temporary file is created in this
327 directory, otherwise it is created in the default system directory for the
328 temporary files or in the current directory.
330 If the function succeeds, the temporary file is actually created. If
\rtfsp
331 {\it fileTemp
} is not
{\tt NULL
}, this file will be opened using the name of
332 the temporary file. When possible, this is done in an atomic way ensuring that
333 no race condition occurs between the temporary file name generation and opening
334 it which could often lead to security compromise on the multiuser systems.
335 If
{\it fileTemp
} is
{\tt NULL
}, the file is only created, but not opened.
337 Under Unix, the temporary file will have read and write permissions for the
338 owner only to minimize the security problems.
340 \wxheading{Parameters
}
342 \docparam{prefix
}{Prefix to use for the temporary file name construction
}
344 \docparam{fileTemp
}{The file to open or
{\tt NULL
} to just get the name
}
346 \wxheading{Return value
}
348 The full temporary file name or an empty string on error.
351 \membersection{wxFileName::DirExists
}\label{wxfilenamedirexists
}
353 \constfunc{bool
}{DirExists
}{\void}
355 \func{static bool
}{DirExists
}{\param{const wxString\&
}{dir
}}
357 Returns
{\tt true
} if the directory with this name exists.
360 \membersection{wxFileName::DirName
}\label{wxfilenamedirname
}
362 \func{static wxFileName
}{DirName
}{\param{const wxString\&
}{dir
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
364 Returns the object corresponding to the directory with the given name.
365 The
{\it dir
} parameter may have trailing path separator or not.
369 \membersection{wxFileName::FileExists
}\label{wxfilenamefileexists
}
371 \constfunc{bool
}{FileExists
}{\void}
373 \func{static bool
}{FileExists
}{\param{const wxString\&
}{file
}}
375 Returns
{\tt true
} if the file with this name exists.
379 \helpref{DirExists
}{wxfilenamedirexists
}
383 \membersection{wxFileName::FileName
}\label{wxfilenamefilename
}
385 \func{static wxFileName
}{FileName
}{\param{const wxString\&
}{file
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
387 Returns the file name object corresponding to the given
{\it file
}. This
388 function exists mainly for symmetry with
\helpref{DirName
}{wxfilenamedirname
}.
392 \membersection{wxFileName::GetCwd
}\label{wxfilenamegetcwd
}
394 \func{static wxString
}{GetCwd
}{\param{const wxString\&
}{volume = ""
}}
396 Retrieves the value of the current working directory on the specified volume. If
397 the volume is empty, the program's current working directory is returned for the
400 \wxheading{Return value
}
402 The string containing the current working directory or an empty string on
407 \helpref{AssignCwd
}{wxfilenameassigncwd
}
410 \membersection{wxFileName::GetDirCount
}\label{wxfilenamegetdircount
}
412 \constfunc{size
\_t}{GetDirCount
}{\void}
414 Returns the number of directories in the file name.
417 \membersection{wxFileName::GetDirs
}\label{wxfilenamegetdirs
}
419 \constfunc{const wxArrayString\&
}{GetDirs
}{\void}
421 Returns the directories in string array form.
424 \membersection{wxFileName::GetExt
}\label{wxfilenamegetext
}
426 \constfunc{wxString
}{GetExt
}{\void}
428 Returns the file name extension.
431 \membersection{wxFileName::GetForbiddenChars
}\label{wxfilenamegetforbiddenchars
}
433 \func{static wxString
}{GetForbiddenChars
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
435 Returns the characters that can't be used in filenames and directory names for the specified format.
438 \membersection{wxFileName::GetFormat
}\label{wxfilenamegetformat
}
440 \func{static wxPathFormat
}{GetFormat
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
442 Returns the canonical path format for this platform.
445 \membersection{wxFileName::GetFullName
}\label{wxfilenamegetfullname
}
447 \constfunc{wxString
}{GetFullName
}{\void}
449 Returns the full name (including extension but excluding directories).
452 \membersection{wxFileName::GetFullPath
}\label{wxfilenamegetfullpath
}
454 \constfunc{wxString
}{GetFullPath
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
456 Returns the full path with name and extension.
459 \membersection{wxFileName::GetHomeDir
}\label{wxfilenamegethomedir
}
461 \func{static wxString
}{GetHomeDir
}{\void}
463 Returns the home directory.
466 \membersection{wxFileName::GetLongPath
}\label{wxfilenamegetlongpath
}
468 \constfunc{wxString
}{GetLongPath
}{\void}
470 Return the long form of the path (returns identity on non-Windows platforms)
473 \membersection{wxFileName::GetModificationTime
}\label{wxfilenamegetmodificationtime
}
475 \constfunc{wxDateTime
}{GetModificationTime
}{\void}
477 Returns the last time the file was last modified.
480 \membersection{wxFileName::GetName
}\label{wxfilenamegetname
}
482 \constfunc{wxString
}{GetName
}{\void}
484 Returns the name part of the filename (without extension).
488 \helpref{GetFullName
}{wxfilenamegetfullname
}
492 \membersection{wxFileName::GetPath
}\label{wxfilenamegetpath
}
494 \constfunc{wxString
}{GetPath
}{\param{int
}{flags =
{\tt wxPATH
\_GET\_VOLUME}},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
496 Returns the path part of the filename (without the name or extension). The
497 possible flags values are:
500 \begin{twocollist
}\itemsep=
0pt
501 \twocolitem{{\bf wxPATH
\_GET\_VOLUME}}{Return the path with the volume (does
502 nothing for the filename formats without volumes), otherwise the path without
503 volume part is returned.
}
504 \twocolitem{{\bf wxPATH
\_GET\_SEPARATOR}}{Return the path with the trailing
505 separator, if this flag is not given there will be no separator at the end of
510 \membersection{wxFileName::GetPathSeparator
}\label{wxfilenamegetpathseparator
}
512 \func{static wxChar
}{GetPathSeparator
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
514 Returns the usually used path separator for this format. For all formats but
515 {\tt wxPATH
\_DOS} there is only one path separator anyhow, but for DOS there
516 are two of them and the native one, i.e. the backslash is returned by this
521 \helpref{GetPathSeparators
}{wxfilenamegetpathseparators
}
524 \membersection{wxFileName::GetPathSeparators
}\label{wxfilenamegetpathseparators
}
526 \func{static wxString
}{GetPathSeparators
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
528 Returns the string containing all the path separators for this format. For all
529 formats but
{\tt wxPATH
\_DOS} this string contains only one character but for
530 DOS and Windows both
{\tt '/'
} and
{\tt '
\textbackslash'
} may be used as
535 \helpref{GetPathSeparator
}{wxfilenamegetpathseparator
}
538 \membersection{wxFileName::GetPathTerminators
}\label{wxfilenamegetpathterminators
}
540 \func{static wxString
}{GetPathTerminators
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
542 Returns the string of characters which may terminate the path part. This is the
543 same as
\helpref{GetPathSeparators
}{wxfilenamegetpathseparators
} except for VMS
544 path format where $
]$ is used at the end of the path part.
547 \membersection{wxFileName::GetPathWithSep
}\label{wxfilenamegetpathwithsep
}
549 \constfunc{wxString
}{GetPathWithSep
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
551 Returns the path with the trailing separator, useful for appending the name to
554 This is the same as calling
\helpref{GetPath
}{wxfilenamegetpath
}
555 \texttt{(wxPATH
\_GET\_VOLUME | wxPATH
\_GET\_SEPARATOR, format)
}.
558 \membersection{wxFileName::GetShortPath
}\label{wxfilenamegetshortpath
}
560 \constfunc{wxString
}{GetShortPath
}{\void}
562 Return the short form of the path (returns identity on non-Windows platforms).
565 \membersection{wxFileName::GetSize
}\label{wxfilenamegetsize
}
567 \constfunc{wxULongLong
}{GetSize
}{\void}
569 \func{static wxULongLong
}{GetSize
}{\param{const wxString\&
}{filename
}}
571 Returns the size of this file (first form) or the size of the given file (second form).
572 If the file does not exist or its size could not be read (because e.g. the file is locked
573 by another process) the returned value is
{\tt wxInvalidSize
}.
576 \membersection{wxFileName::GetHumanReadableSize
}\label{wxfilenamegethumanreadablesize
}
578 \constfunc{wxString
}{GetHumanReadableSize
}{\param{const wxString\&
}{failmsg = "Not available"
},
\param{int
}{precision =
1}}
580 \func{static wxString
}{GetHumanReadableSize
}{\param{const wxULongLong\&
}{bytes
},
\param{const wxString\&
}{nullsize = "Not available"
},
\param{int
}{precision =
1}}
582 Returns the size of this file (first form) or the given number of bytes (second form)
583 in a human-readable form.
585 If the size could not be retrieved the
{\tt failmsg
} string is returned (first form).
586 If
{\tt bytes
} is
{\tt wxInvalidSize
} or zero, then
{\tt nullsize
} is returned (second form).
588 In case of success, the returned string is a floating-point number with
{\tt precision
} decimal digits
589 followed by the size unit (B, kB, MB, GB, TB: respectively bytes, kilobytes, megabytes, gigabytes, terabytes).
592 \membersection{wxFileName::GetTempDir
}\label{wxfilenamegettempdir
}
594 \func{static wxString
}{GetTempDir
}{\void}
596 Returns the directory used for temporary files.
599 \membersection{wxFileName::GetTimes
}\label{wxfilenamegettimes
}
601 \constfunc{bool
}{GetTimes
}{\param{wxDateTime*
}{dtAccess
},
\param{wxDateTime*
}{dtMod
},
\param{wxDateTime*
}{dtCreate
}}
603 Returns the last access, last modification and creation times. The last access
604 time is updated whenever the file is read or written (or executed in the case
605 of Windows), last modification time is only changed when the file is written
606 to. Finally, the creation time is indeed the time when the file was created
607 under Windows and the inode change time under Unix (as it is impossible to
608 retrieve the real file creation time there anyhow) which can also be changed
609 by many operations after the file creation.
611 If no filename or extension is specified in this instance of wxFileName
612 (and therefore
\helpref{IsDir
}{wxfilenameisdir
} returns
{\tt true
}) then
613 this function will return the directory times of the path specified by
614 \helpref{GetPath
}{wxfilenamegetpath
}, otherwise the file times of the
615 file specified by
\helpref{GetFullPath
}{wxfilenamegetfullpath
}.
617 Any of the pointers may be
{\tt NULL
} if the corresponding time is not
620 \wxheading{Return value
}
622 {\tt true
} on success,
{\tt false
} if we failed to retrieve the times.
625 \membersection{wxFileName::GetVolume
}\label{wxfilenamegetvolume
}
627 \constfunc{wxString
}{GetVolume
}{\void}
629 Returns the string containing the volume for this file name, empty if it
630 doesn't have one or if the file system doesn't support volumes at all (for
634 \membersection{wxFileName::GetVolumeSeparator
}\label{wxfilenamegetvolumeseparator
}
636 \func{static wxString
}{GetVolumeSeparator
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
638 Returns the string separating the volume from the path for this format.
641 \membersection{wxFileName::HasExt
}\label{wxfilenamehasext
}
643 \constfunc{bool
}{HasExt
}{\void}
645 Returns
{\tt true
} if an extension is present.
648 \membersection{wxFileName::HasName
}\label{wxfilenamehasname
}
650 \constfunc{bool
}{HasName
}{\void}
652 Returns
{\tt true
} if a name is present.
655 \membersection{wxFileName::HasVolume
}\label{wxfilenamehasvolume
}
657 \constfunc{bool
}{HasVolume
}{\void}
659 Returns
{\tt true
} if a volume specifier is present.
662 \membersection{wxFileName::InsertDir
}\label{wxfilenameinsertdir
}
664 \func{void
}{InsertDir
}{\param{size
\_t }{before
},
\param{const wxString\&
}{dir
}}
666 Inserts a directory component before the zero-based position in the directory
667 list. Please see
\helpref{AppendDir
}{wxfilenameappenddir
} for important notes.
670 \membersection{wxFileName::IsAbsolute
}\label{wxfilenameisabsolute
}
672 \func{bool
}{IsAbsolute
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
674 Returns
{\tt true
} if this filename is absolute.
677 \membersection{wxFileName::IsCaseSensitive
}\label{wxfilenameiscasesensitive
}
679 \func{static bool
}{IsCaseSensitive
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
681 Returns
{\tt true
} if the file names of this type are case-sensitive.
684 \membersection{wxFileName::IsDirReadable
}\label{wxfilenameisdirreadable
}
686 \constfunc{bool
}{IsDirReadable
}{\void}
688 \func{static bool
}{IsDirReadable
}{\param{const wxString\&
}{dir
}}
690 Returns
{\tt true
} if the directory component of this instance (or given
\arg{dir
})
691 is an existing directory and this process has read permissions on it.
692 Read permissions on a directory mean that you can list the directory contents but it
693 doesn't imply that you have read permissions on the files contained.
696 \membersection{wxFileName::IsDirWritable
}\label{wxfilenameisdirwritable
}
698 \constfunc{bool
}{IsDirWritable
}{\void}
700 \func{static bool
}{IsDirWritable
}{\param{const wxString\&
}{dir
}}
702 Returns
{\tt true
} if the directory component of this instance (or given
\arg{dir
})
703 is an existing directory and this process has write permissions on it.
704 Write permissions on a directory mean that you can create new files in the directory.
707 \membersection{wxFileName::IsFileExecutable
}\label{wxfilenameisfileexecutable
}
709 \constfunc{bool
}{IsFileExecutable
}{\void}
711 \func{static bool
}{IsFileExecutable
}{\param{const wxString\&
}{file
}}
713 Returns
{\tt true
} if a file with this name exists and if this process has execute permissions on it.
716 \membersection{wxFileName::IsFileReadable
}\label{wxfilenameisfilereadable
}
718 \constfunc{bool
}{IsFileReadable
}{\void}
720 \func{static bool
}{IsFileReadable
}{\param{const wxString\&
}{file
}}
722 Returns
{\tt true
} if a file with this name exists and if this process has read permissions on it.
725 \membersection{wxFileName::IsFileWritable
}\label{wxfilenameisfilewritable
}
727 \constfunc{bool
}{IsFileWritable
}{\void}
729 \func{static bool
}{IsFileWritable
}{\param{const wxString\&
}{file
}}
731 Returns
{\tt true
} if a file with this name exists and if this process has write permissions on it.
734 \membersection{wxFileName::IsOk
}\label{wxfilenameisok
}
736 \constfunc{bool
}{IsOk
}{\void}
738 Returns
{\tt true
} if the filename is valid,
{\tt false
} if it is not
739 initialized yet. The assignment functions and
740 \helpref{Clear
}{wxfilenameclear
} may reset the object to the uninitialized,
741 invalid state (the former only do it on failure).
744 \membersection{wxFileName::IsPathSeparator
}\label{wxfilenameispathseparator
}
746 \func{static bool
}{IsPathSeparator
}{\param{wxChar
}{ch
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
748 Returns
{\tt true
} if the char is a path separator for this format.
751 \membersection{wxFileName::IsRelative
}\label{wxfilenameisrelative
}
753 \func{bool
}{IsRelative
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
755 Returns
{\tt true
} if this filename is not absolute.
758 \membersection{wxFileName::IsDir
}\label{wxfilenameisdir
}
760 \constfunc{bool
}{IsDir
}{\void}
762 Returns
{\tt true
} if this object represents a directory,
{\tt false
} otherwise
763 (i.e. if it is a file). Note that this method doesn't test whether the
764 directory or file really exists, you should use
765 \helpref{DirExists
}{wxfilenamedirexists
} or
766 \helpref{FileExists
}{wxfilenamefileexists
} for this.
768 \membersection{wxFileName::MacFindDefaultTypeAndCreator
}\label{wxfilenamemacfinddefaulttypeandcreator
}
770 \func{static bool
}{MacFindDefaultTypeAndCreator
}{\param{const wxString\&
}{ext
},
\param{wxUint32*
}{type
},
\param{wxUint32*
}{creator
}}
772 On Mac OS, gets the common type and creator for the given extension.
774 \membersection{wxFileName::MacRegisterDefaultTypeAndCreator
}\label{wxfilenamemacregisterdefaulttypeandcreator
}
776 \func{static void
}{MacRegisterDefaultTypeAndCreator
}{\param{const wxString\&
}{ext
},
\param{wxUint32
}{type
},
\param{wxUint32
}{creator
}}
778 On Mac OS, registers application defined extensions and their default type and creator.
780 \membersection{wxFileName::MacSetDefaultTypeAndCreator
}\label{wxfilenamemacsetdefaulttypeandcreator
}
782 \func{bool
}{MacSetDefaultTypeAndCreator
}{\void}
784 On Mac OS, looks up the appropriate type and creator from the registration and then sets it.
786 \membersection{wxFileName::MakeAbsolute
}\label{wxfilenamemakeabsolute
}
788 \func{bool
}{MakeAbsolute
}{\param{const wxString\&
}{cwd = wxEmptyString
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
790 Make the file name absolute. This is a shortcut for
791 {\tt \helpref{Normalize
}{wxfilenamenormalize
}(wxPATH
\_NORM\_DOTS | wxPATH
\_NORM\_ABSOLUTE | wxPATH
\_NORM\_TILDE, cwd, format)
}.
795 \helpref{MakeRelativeTo
}{wxfilenamemakerelativeto
},
796 \helpref{Normalize
}{wxfilenamenormalize
},
797 \helpref{IsAbsolute
}{wxfilenameisabsolute
}
800 \membersection{wxFileName::MakeRelativeTo
}\label{wxfilenamemakerelativeto
}
802 \func{bool
}{MakeRelativeTo
}{\param{const wxString\&
}{pathBase = wxEmptyString
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
804 This function tries to put this file name in a form relative to
{\it pathBase
}.
805 In other words, it returns the file name which should be used to access this
806 file if the current directory were
{\it pathBase
}.
808 \docparam{pathBase
}{the directory to use as root, current directory is used by
811 \docparam{format
}{the file name format, native by default
}
813 \wxheading{Return value
}
815 {\tt true
} if the file name has been changed,
{\tt false
} if we failed to do
816 anything with it (currently this only happens if the file name is on a volume
817 different from the volume specified by
{\it pathBase
}).
821 \helpref{Normalize
}{wxfilenamenormalize
}
824 \membersection{wxFileName::Mkdir
}\label{wxfilenamemkdir
}
826 \func{bool
}{Mkdir
}{\param{int
}{perm =
0777},
\param{int
}{flags = $
0$
}}
828 \func{static bool
}{Mkdir
}{\param{const wxString\&
}{dir
},
\param{int
}{perm =
0777},
\param{int
}{flags = $
0$
}}
830 \docparam{dir
}{the directory to create
}
832 \docparam{parm
}{the permissions for the newly created directory
}
834 \docparam{flags
}{if the flags contain
{\tt wxPATH
\_MKDIR\_FULL} flag,
835 try to create each directory in the path and also don't return an error
836 if the target directory already exists.
}
838 \wxheading{Return value
}
840 Returns
{\tt true
} if the directory was successfully created,
{\tt false
}
844 \membersection{wxFileName::Normalize
}\label{wxfilenamenormalize
}
846 \func{bool
}{Normalize
}{\param{int
}{flags = wxPATH
\_NORM\_ALL},
\param{const wxString\&
}{cwd = wxEmptyString
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
848 Normalize the path. With the default flags value, the path will be
849 made absolute, without any ".." and "." and all environment
850 variables will be expanded in it.
852 \docparam{flags
}{The kind of normalization to do with the file name. It can be
853 any or-combination of the following constants:
856 \twocolitem{{\bf wxPATH
\_NORM\_ENV\_VARS}}{replace env vars with their values
}
857 \twocolitem{{\bf wxPATH
\_NORM\_DOTS}}{squeeze all .. and . when possible; if there are too many .. and thus they cannot be all removed,
\false will be returned
}
858 \twocolitem{{\bf wxPATH
\_NORM\_CASE}}{if filesystem is case insensitive, transform to lower case
}
859 \twocolitem{{\bf wxPATH
\_NORM\_ABSOLUTE}}{make the path absolute prepending
\arg{cwd
}}
860 \twocolitem{{\bf wxPATH
\_NORM\_LONG}}{make the path the long form
}
861 \twocolitem{{\bf wxPATH
\_NORM\_SHORTCUT}}{resolve if it is a shortcut (Windows only)
}
862 \twocolitem{{\bf wxPATH
\_NORM\_TILDE}}{replace ~ and ~user (Unix only)
}
863 \twocolitem{{\bf wxPATH
\_NORM\_ALL}}{all of previous flags except
\texttt{wxPATH
\_NORM\_CASE}}
867 \docparam{cwd
}{If not empty, this directory will be used instead of current
868 working directory in normalization (see wxPATH
\_NORM\_ABSOLUTE).
}
870 \docparam{format
}{The file name format to use when processing the paths, native by default.
}
873 \wxheading{Return value
}
875 \true if normalization was successfully or
\false otherwise.
878 \membersection{wxFileName::PrependDir
}\label{wxfilenameprependdir
}
880 \func{void
}{PrependDir
}{\param{const wxString\&
}{dir
}}
882 Prepends a directory to the file path. Please see
883 \helpref{AppendDir
}{wxfilenameappenddir
} for important notes.
887 \membersection{wxFileName::RemoveDir
}\label{wxfilenameremovedir
}
889 \func{void
}{RemoveDir
}{\param{size
\_t }{pos
}}
891 Removes the specified directory component from the path.
895 \helpref{GetDirCount
}{wxfilenamegetdircount
}
898 \membersection{wxFileName::RemoveLastDir
}\label{wxfilenameremovelastdir
}
900 \func{void
}{RemoveLastDir
}{\void}
902 Removes last directory component from the path.
905 \membersection{wxFileName::Rmdir
}\label{wxfilenamermdir
}
907 \func{bool
}{Rmdir
}{\void}
909 \func{static bool
}{Rmdir
}{\param{const wxString\&
}{dir
}}
911 Deletes the specified directory from the file system.
914 \membersection{wxFileName::SameAs
}\label{wxfilenamesameas
}
916 \constfunc{bool
}{SameAs
}{\param{const wxFileName\&
}{filepath
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
918 Compares the filename using the rules of this platform.
921 \membersection{wxFileName::SetCwd
}\label{wxfilenamesetcwd
}
923 \func{bool
}{SetCwd
}{\void}
925 \func{static bool
}{SetCwd
}{\param{const wxString\&
}{cwd
}}
927 Changes the current working directory.
930 \membersection{wxFileName::SetExt
}\label{wxfilenamesetext
}
932 \func{void
}{SetExt
}{\param{const wxString\&
}{ext
}}
934 Sets the extension of the file name. Setting an empty string
935 as the extension will remove the extension resulting in a file
936 name without a trailing dot, unlike a call to
937 \helpref{SetEmptyExt
}{wxfilenamesetemptyext
}.
941 \helpref{SetEmptyExt
}{wxfilenamesetemptyext
}
942 \helpref{ClearExt
}{wxfilenameclearext
}
944 \membersection{wxFileName::SetEmptyExt
}\label{wxfilenamesetemptyext
}
946 \func{void
}{SetEmptyExt
}{\void}
948 Sets the extension of the file name to be an empty extension.
949 This is different from having no extension at all as the file
950 name will have a trailing dot after a call to this method.
954 \helpref{SetExt
}{wxfilenamesetext
}
955 \helpref{ClearExt
}{wxfilenameclearext
}
957 \membersection{wxFileName::SetFullName
}\label{wxfilenamesetfullname
}
959 \func{void
}{SetFullName
}{\param{const wxString\&
}{fullname
}}
961 The full name is the file name and extension (but without the path).
964 \membersection{wxFileName::SetName
}\label{wxfilenamesetname
}
966 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
968 Sets the name part (without extension).
972 \helpref{SetFullName
}{wxfilenamesetfullname
}
975 \membersection{wxFileName::SetTimes
}\label{wxfilenamesettimes
}
977 \func{bool
}{SetTimes
}{\param{const wxDateTime*
}{dtAccess
},
\param{const wxDateTime*
}{dtMod
},
\param{const wxDateTime*
}{dtCreate
}}
979 Sets the file creation and last access/modification times (any of the pointers may be NULL).
982 \membersection{wxFileName::SetVolume
}\label{wxfilenamesetvolume
}
984 \func{void
}{SetVolume
}{\param{const wxString\&
}{volume
}}
986 Sets the volume specifier.
989 \membersection{wxFileName::SplitPath
}\label{wxfilenamesplitpath
}
991 \func{static void
}{SplitPath
}{\param{const wxString\&
}{fullpath
},
\param{wxString*
}{volume
},
\param{wxString*
}{path
},
\param{wxString*
}{name
},
\param{wxString*
}{ext
},
\param{bool
}{*hasExt =
\texttt{NULL
}},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
993 \func{static void
}{SplitPath
}{\param{const wxString\&
}{fullpath
},
\param{wxString*
}{volume
},
\param{wxString*
}{path
},
\param{wxString*
}{name
},
\param{wxString*
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
995 \func{static void
}{SplitPath
}{\param{const wxString\&
}{fullpath
},
\param{wxString*
}{path
},
\param{wxString*
}{name
},
\param{wxString*
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
997 This function splits a full file name into components: the volume (with the
998 first version) path (including the volume in the second version), the base name
999 and the extension. Any of the output parameters (
{\it volume
},
{\it path
},
1000 {\it name
} or
{\it ext
}) may be
{\tt NULL
} if you are not interested in the
1001 value of a particular component. Also,
{\it fullpath
} may be empty on entry.
1003 On return,
{\it path
} contains the file path (without the trailing separator),
1004 {\it name
} contains the file name and
{\it ext
} contains the file extension
1005 without leading dot. All three of them may be empty if the corresponding
1006 component is. The old contents of the strings pointed to by these parameters
1007 will be overwritten in any case (if the pointers are not
{\tt NULL
}).
1009 Note that for a filename ``foo.'' the extension is present, as indicated by the
1010 trailing dot, but empty. If you need to cope with such cases, you should use
1011 \arg{hasExt
} instead of relying on testing whether
\arg{ext
} is empty or not.
1014 \membersection{wxFileName::SplitVolume
}\label{wxfilenamesplitvolume
}
1016 \func{static void
}{SplitVolume
}{\param{const wxString\&
}{fullpath
},
\param{wxString*
}{volume
},
\param{wxString*
}{path
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
1018 Splits the given
\arg{fullpath
} into the volume part (which may be empty) and
1019 the pure path part, not containing any volume.
1021 \wxheading{See also
}
1023 \helpref{SplitPath
}{wxfilenamesplitpath
}
1026 \membersection{wxFileName::Touch
}\label{wxfilenametouch
}
1028 \func{bool
}{Touch
}{\void}
1030 Sets the access and modification times to the current moment.
1033 \membersection{wxFileName::operator=
}\label{wxfilenameoperatorassign
}
1035 \func{wxFileName\& operator
}{operator=
}{\param{const wxFileName\&
}{filename
}}
1037 \func{wxFileName\& operator
}{operator=
}{\param{const wxString\&
}{filename
}}
1039 Assigns the new value to this filename object.
1042 \membersection{wxFileName::operator==
}\label{wxfilenameoperatorequal
}
1044 \constfunc{bool operator
}{operator==
}{\param{const wxFileName\&
}{filename
}}
1046 \constfunc{bool operator
}{operator==
}{\param{const wxString\&
}{filename
}}
1048 Returns
{\tt true
} if the filenames are equal. The string
{\it filenames
} is
1049 interpreted as a path in the native filename format.
1052 \membersection{wxFileName::operator!=
}\label{wxfilenameoperatornotequal
}
1054 \constfunc{bool operator
}{operator!=
}{\param{const wxFileName\&
}{filename
}}
1056 \constfunc{bool operator
}{operator!=
}{\param{const wxString\&
}{filename
}}
1058 Returns
{\tt true
} if the filenames are different. The string
{\it filenames
}
1059 is interpreted as a path in the native filename format.