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 The same can be done using the static method
\helpref{wxFileName::DirName
}{wxfilenamedirname
}:
34 wxFileName dirname = wxFileName::DirName( wxT("C:
\mydir") );
35 MyMethod( dirname.GetPath() );
38 Accordingly, methods dealing with directories or directory names
39 like
\helpref{IsDirReadable
}{wxfilenameisdirreadable
} use
40 \helpref{GetPath
}{wxfilenamegetpath
} whereas methods dealing
41 with file names like
\helpref{IsFileReadable
}{wxfilenameisfilereadable
}
42 use
\helpref{GetFullPath
}{wxfilenamegetfullpath
}.
44 If it is not known wether a string contains a directory name or
45 a complete file name (such as when interpreting user input) you need to use
46 the static function
\helpref{wxFileName::DirExists
}{wxfilenamedirexists
}
47 (or its identical variants
\helpref{wxDir::Exists
}{wxdirexists
} and
48 \helpref{wxDirExists
}{functionwxdirexists
}) and construct the wxFileName
49 instance accordingly. This will only work if the directory actually exists,
54 // get input from user
57 if (wxDirExists(user_input))
58 fname.AssignDir( user_input );
60 fname.Assign( user_input );
63 \wxheading{Derived from
}
67 \wxheading{Include files
}
71 \wxheading{Data structures
}
73 Many wxFileName methods accept the path format argument which is by
\rtfsp
74 {\tt wxPATH
\_NATIVE} by default meaning to use the path format native for the
77 The path format affects the operation of wxFileName functions in several ways:
78 first and foremost, it defines the path separator character to use, but it also
79 affects other things such as whether the path has the drive part or not.
84 wxPATH_NATIVE =
0, // the path format for the current platform
86 wxPATH_BEOS = wxPATH_UNIX,
89 wxPATH_WIN = wxPATH_DOS,
90 wxPATH_OS2 = wxPATH_DOS,
93 wxPATH_MAX // Not a valid value for specifying path format
97 \latexignore{\rtfignore{\wxheading{Function groups
}}}
100 \membersection{File name format
}\label{filenameformat
}
102 wxFileName currently supports the file names in the Unix, DOS/Windows, Mac OS
103 and VMS formats. Although these formats are quite different, wxFileName tries
104 to treat them all in the same generic way. It supposes that all file names
105 consist of the following parts: the volume (also known as drive under Windows
106 or device under VMS), the path which is a sequence of directory names separated
107 by the
\helpref{path separators
}{wxfilenamegetpathseparators
} and the full
108 filename itself which, in turn, is composed from the base file name and the
109 extension. All of the individual components of the file name may be empty and,
110 for example, the volume name is always empty under Unix, but if they are all
111 empty simultaneously, the filename object is considered to be in an invalid
112 state and
\helpref{IsOk
}{wxfilenameisok
} returns
{\tt false
} for it.
114 File names can be case-sensitive or not, the function
\rtfsp
115 \helpref{IsCaseSensitive
}{wxfilenameiscasesensitive
} allows to determine this.
117 The rules for determining whether the file name is absolute or relative also
118 depend on the file name format and the only portable way to answer this
119 question is to use
\helpref{IsAbsolute
}{wxfilenameisabsolute
} or
\rtfsp
120 \helpref{IsRelative
}{wxfilenameisrelative
} method. Note that on Windows, "X:"
121 refers to the current working directory on drive X. Therefore, a wxFileName
122 instance constructed from for example "X:dir/file.ext" treats the portion
123 beyond drive separator as being relative to that directory.
125 To ensure that the filename is absolute, you may use
\rtfsp
126 \helpref{MakeAbsolute
}{wxfilenamemakeabsolute
}. There is also an inverse
127 function
\helpref{MakeRelativeTo
}{wxfilenamemakerelativeto
} which undoes
128 what
\helpref{Normalize(wxPATH
\_NORM\_DOTS)
}{wxfilenamenormalize
} does.
130 Other functions returning information about the file format provided by this
131 class are
\helpref{GetVolumeSeparator
}{wxfilenamegetvolumeseparator
},
\rtfsp
132 \helpref{IsPathSeparator
}{wxfilenameispathseparator
}.
135 \membersection{File name construction
}\label{filenameconstruction
}
137 You can initialize a wxFileName instance using one of the following functions:
139 \helpref{wxFileName constructors
}{wxfilenamewxfilename
}\\
140 \helpref{Assign
}{wxfilenameassign
}\\
141 \helpref{AssignCwd
}{wxfilenameassigncwd
}\\
142 \helpref{AssignDir
}{wxfilenameassigndir
}\\
143 \helpref{AssignHomeDir
}{wxfilenameassignhomedir
}\\
144 \helpref{AssignHomeTempFileName
}{wxfilenameassigntempfilename
}\\
145 \helpref{DirName
}{wxfilenameassigndirname
}\\
146 \helpref{FileName
}{wxfilenameassignfilename
}\\
147 \helpref{operator $=$
}{wxfilenameoperatorassign
}
150 \membersection{File tests
}\label{filetests
}
152 Before doing other tests, you should use
\helpref{IsOk
}{wxfilenameisok
} to
153 verify that the filename is well defined. If it is,
\rtfsp
154 \helpref{FileExists
}{wxfilenamefileexists
} can be used to test whether a file
155 with such name exists and
\helpref{DirExists
}{wxfilenamedirexists
} can be used
156 to test for directory existence.
158 File names should be compared using
\helpref{SameAs
}{wxfilenamesameas
} method
159 or
\helpref{operator $==$
}{wxfilenameoperatorequal
}.
161 For testing basic access modes, you can use:
163 \helpref{IsDirWritable
}{wxfilenameisdirwritable
}\\
164 \helpref{IsDirReadable
}{wxfilenameisdirreadable
}\\
165 \helpref{IsFileWritable
}{wxfilenameisfilewritable
}\\
166 \helpref{IsFileReadable
}{wxfilenameisfilereadable
}\\
167 \helpref{IsFileExecutable
}{wxfilenameisfileexecutable
}
170 \membersection{File name components
}\label{filenamecomponents
}
172 These functions allow to examine and modify the individual directories of the
175 \helpref{AppendDir
}{wxfilenameappenddir
}\\
176 \helpref{InsertDir
}{wxfilenameinsertdir
}\\
177 \helpref{GetDirCount
}{wxfilenamegetdircount
}
178 \helpref{PrependDir
}{wxfilenameprependdir
}\\
179 \helpref{RemoveDir
}{wxfilenameremovedir
}\\
180 \helpref{RemoveLastDir
}{wxfilenameremovelastdir
}
182 To change the components of the file name individually you can use the
185 \helpref{GetExt
}{wxfilenamegetext
}\\
186 \helpref{GetName
}{wxfilenamegetname
}\\
187 \helpref{GetVolume
}{wxfilenamegetvolume
}\\
188 \helpref{HasExt
}{wxfilenamehasext
}\\
189 \helpref{HasName
}{wxfilenamehasname
}\\
190 \helpref{HasVolume
}{wxfilenamehasvolume
}\\
191 \helpref{SetExt
}{wxfilenamesetext
}\\
192 \helpref{ClearExt
}{wxfilenameclearext
}\\
193 \helpref{SetEmptyExt
}{wxfilenamesetemptyext
}\\
194 \helpref{SetName
}{wxfilenamesetname
}\\
195 \helpref{SetVolume
}{wxfilenamesetvolume
}\\
198 \membersection{Operations
}\label{filenameoperations
}
200 These methods allow to work with the file creation, access and modification
201 times. Note that not all filesystems under all platforms implement these times
202 in the same way. For example, the access time under Windows has a resolution of
203 one day (so it is really the access date and not time). The access time may be
204 updated when the file is executed or not depending on the platform.
206 \helpref{GetModificationTime
}{wxfilenamegetmodificationtime
}\\
207 \helpref{GetTimes
}{wxfilenamegettimes
}\\
208 \helpref{SetTimes
}{wxfilenamesettimes
}\\
209 \helpref{Touch
}{wxfilenametouch
}
211 Other file system operations functions are:
213 \helpref{Mkdir
}{wxfilenamemkdir
}\\
214 \helpref{Rmdir
}{wxfilenamermdir
}
216 \latexignore{\rtfignore{\wxheading{Members
}}}
219 \membersection{wxFileName::wxFileName
}\label{wxfilenamewxfilename
}
221 \func{}{wxFileName
}{\void}
225 \func{}{wxFileName
}{\param{const wxFileName\&
}{filename
}}
229 \func{}{wxFileName
}{\param{const wxString\&
}{fullpath
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
231 Constructor taking a full filename. If it terminates with a '/', a directory path
232 is constructed (the name will be empty), otherwise a file name and
233 extension are extracted from it.
235 \func{}{wxFileName
}{\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
237 Constructor from a directory name and a file name.
239 \func{}{wxFileName
}{\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
241 Constructor from a directory name, base file name and extension.
243 \func{}{wxFileName
}{\param{const wxString\&
}{volume
},
\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
245 Constructor from a volume name, a directory name, base file name and extension.
248 \membersection{wxFileName::AppendDir
}\label{wxfilenameappenddir
}
250 \func{void
}{AppendDir
}{\param{const wxString\&
}{dir
}}
252 Appends a directory component to the path. This component should contain a
253 single directory name level, i.e. not contain any path or volume separators nor
254 should it be empty, otherwise the function does nothing (and generates an
255 assert failure in debug build).
258 \membersection{wxFileName::Assign
}\label{wxfilenameassign
}
260 \func{void
}{Assign
}{\param{const wxFileName\&
}{filepath
}}
262 \func{void
}{Assign
}{\param{const wxString\&
}{fullpath
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
264 \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}}
266 \func{void
}{Assign
}{\param{const wxString\&
}{volume
},
\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
268 \func{void
}{Assign
}{\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
270 \func{void
}{Assign
}{\param{const wxString\&
}{path
},
\param{const wxString\&
}{name
},
\param{const wxString\&
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
272 Creates the file name from various combinations of data.
275 \membersection{wxFileName::AssignCwd
}\label{wxfilenameassigncwd
}
277 \func{static void
}{AssignCwd
}{\param{const wxString\&
}{volume = wxEmptyString
}}
279 Makes this object refer to the current working directory on the specified
280 volume (or current volume if
{\it volume
} is empty).
284 \helpref{GetCwd
}{wxfilenamegetcwd
}
287 \membersection{wxFileName::AssignDir
}\label{wxfilenameassigndir
}
289 \func{void
}{AssignDir
}{\param{const wxString\&
}{dir
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
291 Sets this file name object to the given directory name. The name and extension
295 \membersection{wxFileName::AssignHomeDir
}\label{wxfilenameassignhomedir
}
297 \func{void
}{AssignHomeDir
}{\void}
299 Sets this file name object to the home directory.
302 \membersection{wxFileName::AssignTempFileName
}\label{wxfilenameassigntempfilename
}
304 \func{void
}{AssignTempFileName
}{\param{const wxString\&
}{prefix
},
\param{wxFile *
}{fileTemp =
{\tt NULL
}}}
306 The function calls
\helpref{CreateTempFileName
}{wxfilenamecreatetempfilename
} to
307 create a temporary file and sets this object to the name of the file. If a
308 temporary file couldn't be created, the object is put into the
\rtfsp
309 \helpref{invalid
}{wxfilenameisok
} state.
312 \membersection{wxFileName::Clear
}\label{wxfilenameclear
}
314 \func{void
}{Clear
}{\void}
316 Reset all components to default, uninitialized state.
319 \membersection{wxFileName::ClearExt
}\label{wxfilenameclearext
}
321 \func{void
}{SetClearExt
}{\void}
323 Removes the extension from the file name resulting in a
324 file name with no trailing dot.
328 \helpref{SetExt
}{wxfilenamesetext
}
329 \helpref{SetEmptyExt
}{wxfilenamesetemptyext
}
331 \membersection{wxFileName::CreateTempFileName
}\label{wxfilenamecreatetempfilename
}
333 \func{static wxString
}{CreateTempFileName
}{\param{const wxString\&
}{prefix
},
\param{wxFile *
}{fileTemp =
{\tt NULL
}}}
335 Returns a temporary file name starting with the given
{\it prefix
}. If
336 the
{\it prefix
} is an absolute path, the temporary file is created in this
337 directory, otherwise it is created in the default system directory for the
338 temporary files or in the current directory.
340 If the function succeeds, the temporary file is actually created. If
\rtfsp
341 {\it fileTemp
} is not
{\tt NULL
}, this file will be opened using the name of
342 the temporary file. When possible, this is done in an atomic way ensuring that
343 no race condition occurs between the temporary file name generation and opening
344 it which could often lead to security compromise on the multiuser systems.
345 If
{\it fileTemp
} is
{\tt NULL
}, the file is only created, but not opened.
347 Under Unix, the temporary file will have read and write permissions for the
348 owner only to minimize the security problems.
350 \wxheading{Parameters
}
352 \docparam{prefix
}{Prefix to use for the temporary file name construction
}
354 \docparam{fileTemp
}{The file to open or
{\tt NULL
} to just get the name
}
356 \wxheading{Return value
}
358 The full temporary file name or an empty string on error.
361 \membersection{wxFileName::DirExists
}\label{wxfilenamedirexists
}
363 \constfunc{bool
}{DirExists
}{\void}
365 \func{static bool
}{DirExists
}{\param{const wxString\&
}{dir
}}
367 Returns
{\tt true
} if the directory with this name exists.
370 \membersection{wxFileName::DirName
}\label{wxfilenamedirname
}
372 \func{static wxFileName
}{DirName
}{\param{const wxString\&
}{dir
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
374 Returns the object corresponding to the directory with the given name.
375 The
{\it dir
} parameter may have trailing path separator or not.
379 \membersection{wxFileName::FileExists
}\label{wxfilenamefileexists
}
381 \constfunc{bool
}{FileExists
}{\void}
383 \func{static bool
}{FileExists
}{\param{const wxString\&
}{file
}}
385 Returns
{\tt true
} if the file with this name exists.
389 \helpref{DirExists
}{wxfilenamedirexists
}
393 \membersection{wxFileName::FileName
}\label{wxfilenamefilename
}
395 \func{static wxFileName
}{FileName
}{\param{const wxString\&
}{file
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
397 Returns the file name object corresponding to the given
{\it file
}. This
398 function exists mainly for symmetry with
\helpref{DirName
}{wxfilenamedirname
}.
402 \membersection{wxFileName::GetCwd
}\label{wxfilenamegetcwd
}
404 \func{static wxString
}{GetCwd
}{\param{const wxString\&
}{volume = ""
}}
406 Retrieves the value of the current working directory on the specified volume. If
407 the volume is empty, the program's current working directory is returned for the
410 \wxheading{Return value
}
412 The string containing the current working directory or an empty string on
417 \helpref{AssignCwd
}{wxfilenameassigncwd
}
420 \membersection{wxFileName::GetDirCount
}\label{wxfilenamegetdircount
}
422 \constfunc{size
\_t}{GetDirCount
}{\void}
424 Returns the number of directories in the file name.
427 \membersection{wxFileName::GetDirs
}\label{wxfilenamegetdirs
}
429 \constfunc{const wxArrayString\&
}{GetDirs
}{\void}
431 Returns the directories in string array form.
434 \membersection{wxFileName::GetExt
}\label{wxfilenamegetext
}
436 \constfunc{wxString
}{GetExt
}{\void}
438 Returns the file name extension.
441 \membersection{wxFileName::GetForbiddenChars
}\label{wxfilenamegetforbiddenchars
}
443 \func{static wxString
}{GetForbiddenChars
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
445 Returns the characters that can't be used in filenames and directory names for the specified format.
448 \membersection{wxFileName::GetFormat
}\label{wxfilenamegetformat
}
450 \func{static wxPathFormat
}{GetFormat
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
452 Returns the canonical path format for this platform.
455 \membersection{wxFileName::GetFullName
}\label{wxfilenamegetfullname
}
457 \constfunc{wxString
}{GetFullName
}{\void}
459 Returns the full name (including extension but excluding directories).
462 \membersection{wxFileName::GetFullPath
}\label{wxfilenamegetfullpath
}
464 \constfunc{wxString
}{GetFullPath
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
466 Returns the full path with name and extension.
469 \membersection{wxFileName::GetHomeDir
}\label{wxfilenamegethomedir
}
471 \func{static wxString
}{GetHomeDir
}{\void}
473 Returns the home directory.
476 \membersection{wxFileName::GetLongPath
}\label{wxfilenamegetlongpath
}
478 \constfunc{wxString
}{GetLongPath
}{\void}
480 Return the long form of the path (returns identity on non-Windows platforms)
483 \membersection{wxFileName::GetModificationTime
}\label{wxfilenamegetmodificationtime
}
485 \constfunc{wxDateTime
}{GetModificationTime
}{\void}
487 Returns the last time the file was last modified.
490 \membersection{wxFileName::GetName
}\label{wxfilenamegetname
}
492 \constfunc{wxString
}{GetName
}{\void}
494 Returns the name part of the filename (without extension).
498 \helpref{GetFullName
}{wxfilenamegetfullname
}
502 \membersection{wxFileName::GetPath
}\label{wxfilenamegetpath
}
504 \constfunc{wxString
}{GetPath
}{\param{int
}{flags =
{\tt wxPATH
\_GET\_VOLUME}},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
506 Returns the path part of the filename (without the name or extension). The
507 possible flags values are:
510 \begin{twocollist
}\itemsep=
0pt
511 \twocolitem{{\bf wxPATH
\_GET\_VOLUME}}{Return the path with the volume (does
512 nothing for the filename formats without volumes), otherwise the path without
513 volume part is returned.
}
514 \twocolitem{{\bf wxPATH
\_GET\_SEPARATOR}}{Return the path with the trailing
515 separator, if this flag is not given there will be no separator at the end of
520 \membersection{wxFileName::GetPathSeparator
}\label{wxfilenamegetpathseparator
}
522 \func{static wxChar
}{GetPathSeparator
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
524 Returns the usually used path separator for this format. For all formats but
525 {\tt wxPATH
\_DOS} there is only one path separator anyhow, but for DOS there
526 are two of them and the native one, i.e. the backslash is returned by this
531 \helpref{GetPathSeparators
}{wxfilenamegetpathseparators
}
534 \membersection{wxFileName::GetPathSeparators
}\label{wxfilenamegetpathseparators
}
536 \func{static wxString
}{GetPathSeparators
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
538 Returns the string containing all the path separators for this format. For all
539 formats but
{\tt wxPATH
\_DOS} this string contains only one character but for
540 DOS and Windows both
{\tt '/'
} and
{\tt '
\textbackslash'
} may be used as
545 \helpref{GetPathSeparator
}{wxfilenamegetpathseparator
}
548 \membersection{wxFileName::GetPathTerminators
}\label{wxfilenamegetpathterminators
}
550 \func{static wxString
}{GetPathTerminators
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
552 Returns the string of characters which may terminate the path part. This is the
553 same as
\helpref{GetPathSeparators
}{wxfilenamegetpathseparators
} except for VMS
554 path format where $
]$ is used at the end of the path part.
557 \membersection{wxFileName::GetPathWithSep
}\label{wxfilenamegetpathwithsep
}
559 \constfunc{wxString
}{GetPathWithSep
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
561 Returns the path with the trailing separator, useful for appending the name to
564 This is the same as calling
\helpref{GetPath
}{wxfilenamegetpath
}
565 \texttt{(wxPATH
\_GET\_VOLUME | wxPATH
\_GET\_SEPARATOR, format)
}.
568 \membersection{wxFileName::GetShortPath
}\label{wxfilenamegetshortpath
}
570 \constfunc{wxString
}{GetShortPath
}{\void}
572 Return the short form of the path (returns identity on non-Windows platforms).
575 \membersection{wxFileName::GetSize
}\label{wxfilenamegetsize
}
577 \constfunc{wxULongLong
}{GetSize
}{\void}
579 \func{static wxULongLong
}{GetSize
}{\param{const wxString\&
}{filename
}}
581 Returns the size of this file (first form) or the size of the given file (second form).
582 If the file does not exist or its size could not be read (because e.g. the file is locked
583 by another process) the returned value is
{\tt wxInvalidSize
}.
586 \membersection{wxFileName::GetHumanReadableSize
}\label{wxfilenamegethumanreadablesize
}
588 \constfunc{wxString
}{GetHumanReadableSize
}{\param{const wxString\&
}{failmsg = "Not available"
},
\param{int
}{precision =
1}}
590 \func{static wxString
}{GetHumanReadableSize
}{\param{const wxULongLong\&
}{bytes
},
\param{const wxString\&
}{nullsize = "Not available"
},
\param{int
}{precision =
1}}
592 Returns the size of this file (first form) or the given number of bytes (second form)
593 in a human-readable form.
595 If the size could not be retrieved the
{\tt failmsg
} string is returned (first form).
596 If
{\tt bytes
} is
{\tt wxInvalidSize
} or zero, then
{\tt nullsize
} is returned (second form).
598 In case of success, the returned string is a floating-point number with
{\tt precision
} decimal digits
599 followed by the size unit (B, kB, MB, GB, TB: respectively bytes, kilobytes, megabytes, gigabytes, terabytes).
602 \membersection{wxFileName::GetTempDir
}\label{wxfilenamegettempdir
}
604 \func{static wxString
}{GetTempDir
}{\void}
606 Returns the directory used for temporary files.
609 \membersection{wxFileName::GetTimes
}\label{wxfilenamegettimes
}
611 \constfunc{bool
}{GetTimes
}{\param{wxDateTime*
}{dtAccess
},
\param{wxDateTime*
}{dtMod
},
\param{wxDateTime*
}{dtCreate
}}
613 Returns the last access, last modification and creation times. The last access
614 time is updated whenever the file is read or written (or executed in the case
615 of Windows), last modification time is only changed when the file is written
616 to. Finally, the creation time is indeed the time when the file was created
617 under Windows and the inode change time under Unix (as it is impossible to
618 retrieve the real file creation time there anyhow) which can also be changed
619 by many operations after the file creation.
621 If no filename or extension is specified in this instance of wxFileName
622 (and therefore
\helpref{IsDir
}{wxfilenameisdir
} returns
{\tt true
}) then
623 this function will return the directory times of the path specified by
624 \helpref{GetPath
}{wxfilenamegetpath
}, otherwise the file times of the
625 file specified by
\helpref{GetFullPath
}{wxfilenamegetfullpath
}.
627 Any of the pointers may be
{\tt NULL
} if the corresponding time is not
630 \wxheading{Return value
}
632 {\tt true
} on success,
{\tt false
} if we failed to retrieve the times.
635 \membersection{wxFileName::GetVolume
}\label{wxfilenamegetvolume
}
637 \constfunc{wxString
}{GetVolume
}{\void}
639 Returns the string containing the volume for this file name, empty if it
640 doesn't have one or if the file system doesn't support volumes at all (for
644 \membersection{wxFileName::GetVolumeSeparator
}\label{wxfilenamegetvolumeseparator
}
646 \func{static wxString
}{GetVolumeSeparator
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
648 Returns the string separating the volume from the path for this format.
651 \membersection{wxFileName::HasExt
}\label{wxfilenamehasext
}
653 \constfunc{bool
}{HasExt
}{\void}
655 Returns
{\tt true
} if an extension is present.
658 \membersection{wxFileName::HasName
}\label{wxfilenamehasname
}
660 \constfunc{bool
}{HasName
}{\void}
662 Returns
{\tt true
} if a name is present.
665 \membersection{wxFileName::HasVolume
}\label{wxfilenamehasvolume
}
667 \constfunc{bool
}{HasVolume
}{\void}
669 Returns
{\tt true
} if a volume specifier is present.
672 \membersection{wxFileName::InsertDir
}\label{wxfilenameinsertdir
}
674 \func{void
}{InsertDir
}{\param{size
\_t }{before
},
\param{const wxString\&
}{dir
}}
676 Inserts a directory component before the zero-based position in the directory
677 list. Please see
\helpref{AppendDir
}{wxfilenameappenddir
} for important notes.
680 \membersection{wxFileName::IsAbsolute
}\label{wxfilenameisabsolute
}
682 \func{bool
}{IsAbsolute
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
684 Returns
{\tt true
} if this filename is absolute.
687 \membersection{wxFileName::IsCaseSensitive
}\label{wxfilenameiscasesensitive
}
689 \func{static bool
}{IsCaseSensitive
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
691 Returns
{\tt true
} if the file names of this type are case-sensitive.
694 \membersection{wxFileName::IsDirReadable
}\label{wxfilenameisdirreadable
}
696 \constfunc{bool
}{IsDirReadable
}{\void}
698 \func{static bool
}{IsDirReadable
}{\param{const wxString\&
}{dir
}}
700 Returns
{\tt true
} if the directory component of this instance (or given
\arg{dir
})
701 is an existing directory and this process has read permissions on it.
702 Read permissions on a directory mean that you can list the directory contents but it
703 doesn't imply that you have read permissions on the files contained.
706 \membersection{wxFileName::IsDirWritable
}\label{wxfilenameisdirwritable
}
708 \constfunc{bool
}{IsDirWritable
}{\void}
710 \func{static bool
}{IsDirWritable
}{\param{const wxString\&
}{dir
}}
712 Returns
{\tt true
} if the directory component of this instance (or given
\arg{dir
})
713 is an existing directory and this process has write permissions on it.
714 Write permissions on a directory mean that you can create new files in the directory.
717 \membersection{wxFileName::IsFileExecutable
}\label{wxfilenameisfileexecutable
}
719 \constfunc{bool
}{IsFileExecutable
}{\void}
721 \func{static bool
}{IsFileExecutable
}{\param{const wxString\&
}{file
}}
723 Returns
{\tt true
} if a file with this name exists and if this process has execute permissions on it.
726 \membersection{wxFileName::IsFileReadable
}\label{wxfilenameisfilereadable
}
728 \constfunc{bool
}{IsFileReadable
}{\void}
730 \func{static bool
}{IsFileReadable
}{\param{const wxString\&
}{file
}}
732 Returns
{\tt true
} if a file with this name exists and if this process has read permissions on it.
735 \membersection{wxFileName::IsFileWritable
}\label{wxfilenameisfilewritable
}
737 \constfunc{bool
}{IsFileWritable
}{\void}
739 \func{static bool
}{IsFileWritable
}{\param{const wxString\&
}{file
}}
741 Returns
{\tt true
} if a file with this name exists and if this process has write permissions on it.
744 \membersection{wxFileName::IsOk
}\label{wxfilenameisok
}
746 \constfunc{bool
}{IsOk
}{\void}
748 Returns
{\tt true
} if the filename is valid,
{\tt false
} if it is not
749 initialized yet. The assignment functions and
750 \helpref{Clear
}{wxfilenameclear
} may reset the object to the uninitialized,
751 invalid state (the former only do it on failure).
754 \membersection{wxFileName::IsPathSeparator
}\label{wxfilenameispathseparator
}
756 \func{static bool
}{IsPathSeparator
}{\param{wxChar
}{ch
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
758 Returns
{\tt true
} if the char is a path separator for this format.
761 \membersection{wxFileName::IsRelative
}\label{wxfilenameisrelative
}
763 \func{bool
}{IsRelative
}{\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
765 Returns
{\tt true
} if this filename is not absolute.
768 \membersection{wxFileName::IsDir
}\label{wxfilenameisdir
}
770 \constfunc{bool
}{IsDir
}{\void}
772 Returns
{\tt true
} if this object represents a directory,
{\tt false
} otherwise
773 (i.e. if it is a file). Note that this method doesn't test whether the
774 directory or file really exists, you should use
775 \helpref{DirExists
}{wxfilenamedirexists
} or
776 \helpref{FileExists
}{wxfilenamefileexists
} for this.
778 \membersection{wxFileName::MacFindDefaultTypeAndCreator
}\label{wxfilenamemacfinddefaulttypeandcreator
}
780 \func{static bool
}{MacFindDefaultTypeAndCreator
}{\param{const wxString\&
}{ext
},
\param{wxUint32*
}{type
},
\param{wxUint32*
}{creator
}}
782 On Mac OS, gets the common type and creator for the given extension.
784 \membersection{wxFileName::MacRegisterDefaultTypeAndCreator
}\label{wxfilenamemacregisterdefaulttypeandcreator
}
786 \func{static void
}{MacRegisterDefaultTypeAndCreator
}{\param{const wxString\&
}{ext
},
\param{wxUint32
}{type
},
\param{wxUint32
}{creator
}}
788 On Mac OS, registers application defined extensions and their default type and creator.
790 \membersection{wxFileName::MacSetDefaultTypeAndCreator
}\label{wxfilenamemacsetdefaulttypeandcreator
}
792 \func{bool
}{MacSetDefaultTypeAndCreator
}{\void}
794 On Mac OS, looks up the appropriate type and creator from the registration and then sets it.
796 \membersection{wxFileName::MakeAbsolute
}\label{wxfilenamemakeabsolute
}
798 \func{bool
}{MakeAbsolute
}{\param{const wxString\&
}{cwd = wxEmptyString
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
800 Make the file name absolute. This is a shortcut for
801 {\tt \helpref{Normalize
}{wxfilenamenormalize
}(wxPATH
\_NORM\_DOTS | wxPATH
\_NORM\_ABSOLUTE | wxPATH
\_NORM\_TILDE, cwd, format)
}.
805 \helpref{MakeRelativeTo
}{wxfilenamemakerelativeto
},
806 \helpref{Normalize
}{wxfilenamenormalize
},
807 \helpref{IsAbsolute
}{wxfilenameisabsolute
}
810 \membersection{wxFileName::MakeRelativeTo
}\label{wxfilenamemakerelativeto
}
812 \func{bool
}{MakeRelativeTo
}{\param{const wxString\&
}{pathBase = wxEmptyString
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
814 This function tries to put this file name in a form relative to
{\it pathBase
}.
815 In other words, it returns the file name which should be used to access this
816 file if the current directory were
{\it pathBase
}.
818 \docparam{pathBase
}{the directory to use as root, current directory is used by
821 \docparam{format
}{the file name format, native by default
}
823 \wxheading{Return value
}
825 {\tt true
} if the file name has been changed,
{\tt false
} if we failed to do
826 anything with it (currently this only happens if the file name is on a volume
827 different from the volume specified by
{\it pathBase
}).
831 \helpref{Normalize
}{wxfilenamenormalize
}
834 \membersection{wxFileName::Mkdir
}\label{wxfilenamemkdir
}
836 \func{bool
}{Mkdir
}{\param{int
}{perm =
0777},
\param{int
}{flags = $
0$
}}
838 \func{static bool
}{Mkdir
}{\param{const wxString\&
}{dir
},
\param{int
}{perm =
0777},
\param{int
}{flags = $
0$
}}
840 \docparam{dir
}{the directory to create
}
842 \docparam{parm
}{the permissions for the newly created directory
}
844 \docparam{flags
}{if the flags contain
{\tt wxPATH
\_MKDIR\_FULL} flag,
845 try to create each directory in the path and also don't return an error
846 if the target directory already exists.
}
848 \wxheading{Return value
}
850 Returns
{\tt true
} if the directory was successfully created,
{\tt false
}
854 \membersection{wxFileName::Normalize
}\label{wxfilenamenormalize
}
856 \func{bool
}{Normalize
}{\param{int
}{flags = wxPATH
\_NORM\_ALL},
\param{const wxString\&
}{cwd = wxEmptyString
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
858 Normalize the path. With the default flags value, the path will be
859 made absolute, without any ".." and "." and all environment
860 variables will be expanded in it.
862 \docparam{flags
}{The kind of normalization to do with the file name. It can be
863 any or-combination of the following constants:
866 \twocolitem{{\bf wxPATH
\_NORM\_ENV\_VARS}}{replace env vars with their values
}
867 \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
}
868 \twocolitem{{\bf wxPATH
\_NORM\_CASE}}{if filesystem is case insensitive, transform to lower case
}
869 \twocolitem{{\bf wxPATH
\_NORM\_ABSOLUTE}}{make the path absolute prepending
\arg{cwd
}}
870 \twocolitem{{\bf wxPATH
\_NORM\_LONG}}{make the path the long form
}
871 \twocolitem{{\bf wxPATH
\_NORM\_SHORTCUT}}{resolve if it is a shortcut (Windows only)
}
872 \twocolitem{{\bf wxPATH
\_NORM\_TILDE}}{replace ~ and ~user (Unix only)
}
873 \twocolitem{{\bf wxPATH
\_NORM\_ALL}}{all of previous flags except
\texttt{wxPATH
\_NORM\_CASE}}
877 \docparam{cwd
}{If not empty, this directory will be used instead of current
878 working directory in normalization (see wxPATH
\_NORM\_ABSOLUTE).
}
880 \docparam{format
}{The file name format to use when processing the paths, native by default.
}
883 \wxheading{Return value
}
885 \true if normalization was successfully or
\false otherwise.
888 \membersection{wxFileName::PrependDir
}\label{wxfilenameprependdir
}
890 \func{void
}{PrependDir
}{\param{const wxString\&
}{dir
}}
892 Prepends a directory to the file path. Please see
893 \helpref{AppendDir
}{wxfilenameappenddir
} for important notes.
897 \membersection{wxFileName::RemoveDir
}\label{wxfilenameremovedir
}
899 \func{void
}{RemoveDir
}{\param{size
\_t }{pos
}}
901 Removes the specified directory component from the path.
905 \helpref{GetDirCount
}{wxfilenamegetdircount
}
908 \membersection{wxFileName::RemoveLastDir
}\label{wxfilenameremovelastdir
}
910 \func{void
}{RemoveLastDir
}{\void}
912 Removes last directory component from the path.
915 \membersection{wxFileName::Rmdir
}\label{wxfilenamermdir
}
917 \func{bool
}{Rmdir
}{\void}
919 \func{static bool
}{Rmdir
}{\param{const wxString\&
}{dir
}}
921 Deletes the specified directory from the file system.
924 \membersection{wxFileName::SameAs
}\label{wxfilenamesameas
}
926 \constfunc{bool
}{SameAs
}{\param{const wxFileName\&
}{filepath
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
928 Compares the filename using the rules of this platform.
931 \membersection{wxFileName::SetCwd
}\label{wxfilenamesetcwd
}
933 \func{bool
}{SetCwd
}{\void}
935 \func{static bool
}{SetCwd
}{\param{const wxString\&
}{cwd
}}
937 Changes the current working directory.
940 \membersection{wxFileName::SetExt
}\label{wxfilenamesetext
}
942 \func{void
}{SetExt
}{\param{const wxString\&
}{ext
}}
944 Sets the extension of the file name. Setting an empty string
945 as the extension will remove the extension resulting in a file
946 name without a trailing dot, unlike a call to
947 \helpref{SetEmptyExt
}{wxfilenamesetemptyext
}.
951 \helpref{SetEmptyExt
}{wxfilenamesetemptyext
}
952 \helpref{ClearExt
}{wxfilenameclearext
}
954 \membersection{wxFileName::SetEmptyExt
}\label{wxfilenamesetemptyext
}
956 \func{void
}{SetEmptyExt
}{\void}
958 Sets the extension of the file name to be an empty extension.
959 This is different from having no extension at all as the file
960 name will have a trailing dot after a call to this method.
964 \helpref{SetExt
}{wxfilenamesetext
}
965 \helpref{ClearExt
}{wxfilenameclearext
}
967 \membersection{wxFileName::SetFullName
}\label{wxfilenamesetfullname
}
969 \func{void
}{SetFullName
}{\param{const wxString\&
}{fullname
}}
971 The full name is the file name and extension (but without the path).
974 \membersection{wxFileName::SetName
}\label{wxfilenamesetname
}
976 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
978 Sets the name part (without extension).
982 \helpref{SetFullName
}{wxfilenamesetfullname
}
985 \membersection{wxFileName::SetTimes
}\label{wxfilenamesettimes
}
987 \func{bool
}{SetTimes
}{\param{const wxDateTime*
}{dtAccess
},
\param{const wxDateTime*
}{dtMod
},
\param{const wxDateTime*
}{dtCreate
}}
989 Sets the file creation and last access/modification times (any of the pointers may be NULL).
992 \membersection{wxFileName::SetVolume
}\label{wxfilenamesetvolume
}
994 \func{void
}{SetVolume
}{\param{const wxString\&
}{volume
}}
996 Sets the volume specifier.
999 \membersection{wxFileName::SplitPath
}\label{wxfilenamesplitpath
}
1001 \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}}
1003 \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}}
1005 \func{static void
}{SplitPath
}{\param{const wxString\&
}{fullpath
},
\param{wxString*
}{path
},
\param{wxString*
}{name
},
\param{wxString*
}{ext
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
1007 This function splits a full file name into components: the volume (with the
1008 first version) path (including the volume in the second version), the base name
1009 and the extension. Any of the output parameters (
{\it volume
},
{\it path
},
1010 {\it name
} or
{\it ext
}) may be
{\tt NULL
} if you are not interested in the
1011 value of a particular component. Also,
{\it fullpath
} may be empty on entry.
1013 On return,
{\it path
} contains the file path (without the trailing separator),
1014 {\it name
} contains the file name and
{\it ext
} contains the file extension
1015 without leading dot. All three of them may be empty if the corresponding
1016 component is. The old contents of the strings pointed to by these parameters
1017 will be overwritten in any case (if the pointers are not
{\tt NULL
}).
1019 Note that for a filename ``foo.'' the extension is present, as indicated by the
1020 trailing dot, but empty. If you need to cope with such cases, you should use
1021 \arg{hasExt
} instead of relying on testing whether
\arg{ext
} is empty or not.
1024 \membersection{wxFileName::SplitVolume
}\label{wxfilenamesplitvolume
}
1026 \func{static void
}{SplitVolume
}{\param{const wxString\&
}{fullpath
},
\param{wxString*
}{volume
},
\param{wxString*
}{path
},
\param{wxPathFormat
}{format = wxPATH
\_NATIVE}}
1028 Splits the given
\arg{fullpath
} into the volume part (which may be empty) and
1029 the pure path part, not containing any volume.
1031 \wxheading{See also
}
1033 \helpref{SplitPath
}{wxfilenamesplitpath
}
1036 \membersection{wxFileName::Touch
}\label{wxfilenametouch
}
1038 \func{bool
}{Touch
}{\void}
1040 Sets the access and modification times to the current moment.
1043 \membersection{wxFileName::operator=
}\label{wxfilenameoperatorassign
}
1045 \func{wxFileName\& operator
}{operator=
}{\param{const wxFileName\&
}{filename
}}
1047 \func{wxFileName\& operator
}{operator=
}{\param{const wxString\&
}{filename
}}
1049 Assigns the new value to this filename object.
1052 \membersection{wxFileName::operator==
}\label{wxfilenameoperatorequal
}
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 equal. The string
{\it filenames
} is
1059 interpreted as a path in the native filename format.
1062 \membersection{wxFileName::operator!=
}\label{wxfilenameoperatornotequal
}
1064 \constfunc{bool operator
}{operator!=
}{\param{const wxFileName\&
}{filename
}}
1066 \constfunc{bool operator
}{operator!=
}{\param{const wxString\&
}{filename
}}
1068 Returns
{\tt true
} if the filenames are different. The string
{\it filenames
}
1069 is interpreted as a path in the native filename format.