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