]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/filename.tex
aead365877d31f51e6f2d5741c1fd055ae517e46
[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{wxWindows 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 \wxheading{Derived from}
23
24 No base class
25
26 \wxheading{Data structures}
27
28 Many wxFileName methods accept the path format argument which is by\rtfsp
29 {\tt wxPATH\_NATIVE} by default meaning to use the path format native for the
30 current platform.
31
32 The path format affects the operation of wxFileName functions in several ways:
33 first and foremost, it defines the path separator character to use, but it also
34 affects other things such as whether the path has the drive part or not.
35
36 \begin{verbatim}
37 enum wxPathFormat
38 {
39 wxPATH_NATIVE = 0, // the path format for the current platform
40 wxPATH_UNIX,
41 wxPATH_MAC,
42 wxPATH_DOS,
43 wxPATH_VMS,
44
45 wxPATH_BEOS = wxPATH_UNIX,
46 wxPATH_WIN = wxPATH_DOS,
47 wxPATH_OS2 = wxPATH_DOS
48 }
49 \end{verbatim}
50
51 The kind of normalization to do with the file name: these values can be
52 or'd together to perform several operations at once in\rtfsp
53 \helpref{Normalize}{wxfilenamenormalize}.
54
55 \begin{verbatim}
56 enum wxPathNormalize
57 {
58 wxPATH_NORM_ENV_VARS = 0x0001, // replace env vars with their values
59 wxPATH_NORM_DOTS = 0x0002, // squeeze all .. and . and prepend cwd
60 wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user
61 wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower
62 wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute
63 wxPATH_NORM_LONG = 0x0020, // make the path the long form
64 wxPATH_NORM_ALL = 0x003f
65 }
66 \end{verbatim}
67
68 \latexignore{\rtfignore{\wxheading{Function groups}}}
69
70 \membersection{File name format}
71
72 wxFileName currently supports the file names in the Unix, DOS/Windows, Mac OS
73 and VMS formats. Although these formats are quite different, wxFileName tries
74 to treat them all in the sam generic way. It supposes that all file names
75 consist of the following parts: the volume (also known as drive under Windows
76 or device under VMS), the path which is a sequence of directory names separated
77 by the \helpref{path separators}{wxfilenamegetpathseparators} and the full
78 filename itself which, in turn, is composed from the base file name and the
79 extension. All of the individual components of the file name may be empty and,
80 for example, the volume name is always empty under Unix, but if they are all
81 empty simultaneously, the filename object is considered to be in an invalid
82 state and \helpref{IsOk}{wxfilenameisok} returns {\tt FALSE} for it.
83
84 File names can be case-sensitive or not, the function\rtfsp
85 \helpref{IsCaseSensitive}{wxfilenameiscasesensitive} allows to determine this.
86
87 The rules for determining if the file name is absolute or relative also depends
88 on the file name format and the only portable way to answer to this question is
89 to use \helpref{IsAbsolute}{wxfilenameisabsolute} method. To ensure that the
90 filename is absolute you may use \helpref{Normalize}{wxfilenamenormalize}.
91
92 Other functions returning information about the file format provided by this
93 class are \helpref{GetVolumeSeparator}{wxfilenamegetvolumeseparator},\rtfsp
94 \helpref{IsPathSeparator}{wxfilenameispathseparator} and\rtfsp
95 \helpref{IsWild}{wxfilenameiswild}.
96
97 \helpref{IsRelative}{wxfilenameisrelative}
98
99 \membersection{File name construction}
100
101 TODO.
102
103 \membersection{File tests}
104
105 Before doing the other tests you should use \helpref{IsOk}{wxfilenameisok} to
106 verify that the filename is well defined. If it is,
107 \helpref{FileExists}{wxfilenamefileexists} can be used to test if a file with
108 such name exists and \helpref{DirExists}{wxfilenamedirexists} - if a directory
109 with this name exists.
110
111 File names should be compared using \helpref{SameAs}{wxfilenamesameas} method
112 or \helpref{$==$}{wxfilenameoperatorequal}.
113
114 \membersection{File name components}
115
116 These functions allow to examine and modify the directories of the path:
117
118 \helpref{AppendDir}{wxfilenameappenddir}\\
119 \helpref{InsertDir}{wxfilenameinsertdir}\\
120 \helpref{GetDirCount}{wxfilenamegetdircount}
121 \helpref{PrependDir}{wxfilenameprependdir}\\
122 \helpref{RemoveDir}{wxfilenameremovedir}
123
124 To change the components of the file name individually you can use the
125 following functions:
126
127 \helpref{GetExt}{wxfilenamegetext}\\
128 \helpref{GetName}{wxfilenamegetname}\\
129 \helpref{GetVolume}{wxfilenamegetvolume}\\
130 \helpref{HasExt}{wxfilenamehasext}\\
131 \helpref{HasName}{wxfilenamehasname}\\
132 \helpref{HasVolume}{wxfilenamehasvolume}\\
133 \helpref{SetExt}{wxfilenamesetext}\\
134 \helpref{SetName}{wxfilenamesetname}\\
135 \helpref{SetVolume}{wxfilenamesetvolume}\\
136
137 \membersection{Operations}
138
139 These methods allow to work with the file creation, access and modification
140 times:
141
142 \helpref{GetModificationTime}{wxfilenamegetmodificationtime}\\
143 \helpref{GetTimes}{wxfilenamegettimes}\\
144 \helpref{SetTimes}{wxfilenamesettimes}\\
145 \helpref{Touch}{wxfilenametouch}
146
147 Other file system operations functions are:
148
149 \helpref{Mkdir}{wxfilenamemkdir}\\
150 \helpref{Rmdir}{wxfilenamermdir}
151
152 \latexignore{\rtfignore{\wxheading{Members}}}
153
154 \membersection{wxFileName::wxFileName}\label{wxfilenamewxfilename}
155
156 \func{}{wxFileName}{\void}
157
158 Default constructor.
159
160 \func{}{wxFileName}{\param{const wxFileName\& }{filename}}
161
162 Copy constructor.
163
164 \func{}{wxFileName}{\param{const wxString\& }{fullpath}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
165
166 From a full filename: if it terminates with a '/', a directory path
167 is contructed (the name will be empty), otherwise a file name and
168 extension are extracted from it
169
170 \func{}{wxFileName}{\param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
171
172 Constructor from a directory name and a file name.
173
174 \func{}{wxFileName}{\param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{const wxString\& }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
175
176 Constructor from a directory name, base file name and extension
177
178 \func{}{wxFileName}{\param{const wxString\& }{volume}, \param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{const wxString\& }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
179
180 Constructor from a volume name, a directory name, base file name and extension
181
182 \membersection{wxFileName::AppendDir}\label{wxfilenameappenddir}
183
184 \func{void}{AppendDir}{\param{const wxString\& }{dir}}
185
186
187 \membersection{wxFileName::Assign}\label{wxfilenameassign}
188
189 \func{void}{Assign}{\param{const wxFileName\& }{filepath}}
190
191 \func{void}{Assign}{\param{const wxString\& }{fullpath}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
192
193 \func{void}{Assign}{\param{const wxString\& }{volume}, \param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{const wxString\& }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
194
195 \func{void}{Assign}{\param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
196
197 \func{void}{Assign}{\param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{const wxString\& }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
198
199
200 \membersection{wxFileName::AssignCwd}\label{wxfilenameassigncwd}
201
202 \func{void}{AssignCwd}{\param{const wxString\& }{volume = ""}}
203
204 Makes this object refer to the current working directory on the specified
205 volume (or current volume if {\it volume} is empty).
206
207 \wxheading{See also}
208
209 \helpref{GetCwd}{wxfilenamegetcwd}
210
211 \membersection{wxFileName::AssignDir}\label{wxfilenameassigndir}
212
213 \func{void}{AssignDir}{\param{const wxString\& }{dir}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
214
215 Set this file name object to the given directory name. The name and extension
216 will be empty.
217
218 \membersection{wxFileName::AssignHomeDir}\label{wxfilenameassignhomedir}
219
220 \func{void}{AssignHomeDir}{\void}
221
222 Set this file name object to the home directory.
223
224 \membersection{wxFileName::AssignTempFileName}\label{wxfilenameassigntempfilename}
225
226 \func{void}{AssignTempFileName}{\param{const wxString\& }{prefix}}
227
228 The function calls \helpref{CreateTempFileName}{wxfilenamecreatetempfilename} to
229 create a temporary file and sets this object to the name of the file. If a
230 temporary file couldn't be created, the object is put into the\rtfsp
231 \helpref{invalid}{wxfilenameisok} state.
232
233 \membersection{wxFileName::Clear}\label{wxfilenameclear}
234
235 \func{void}{Clear}{\void}
236
237 Reset all components to default, uninitialized state.
238
239 \membersection{wxFileName::CreateTempFileName}\label{wxfilenamecreatetempfilename}
240
241 \func{static wxString}{CreateTempFileName}{\param{const wxString\& }{prefix}}
242
243 Returns a temporary file name starting with the given {\it prefix}. If
244 the {\it prefix} is an absolute path, the temporary file is created in this
245 directory, otherwise it is created in the default system directory for the
246 temporary files or in the current directory.
247
248 If the function succeeds, the temporary file is actually created (but not
249 opened) as well. Under Unix, it will have read and write permissions for the
250 owner only.
251
252 \wxheading{Return value}
253
254 The full temporary file name or an empty string on error.
255
256 \membersection{wxFileName::DirExists}\label{wxfilenamedirexists}
257
258 \func{bool}{DirExists}{\void}
259
260 \func{bool}{DirExists}{\param{const wxString\& }{dir}}
261
262 Does the directory with this name exists?
263
264 \membersection{wxFileName::DirName}\label{wxfilenamedirname}
265
266 \func{wxFileName}{DirName}{\param{const wxString\& }{dir}}
267
268 \membersection{wxFileName::FileExists}\label{wxfilenamefileexists}
269
270 \func{bool}{FileExists}{\void}
271
272 \func{bool}{FileExists}{\param{const wxString\& }{file}}
273
274 Does the file with this name exists?
275
276 \membersection{wxFileName::FileName}\label{wxfilenamefilename}
277
278 \func{wxFileName}{FileName}{\param{const wxString\& }{file}}
279
280 static pseudo constructors
281
282 \membersection{wxFileName::GetCwd}\label{wxfilenamegetcwd}
283
284 \func{wxString}{GetCwd}{\param{const wxString\& }{volume = ""}}
285
286 Retrieve the value of the current working directory on the specified volume. If
287 the volume is empty, the programs current working directory is returned for the
288 current volume.
289
290 \wxheading{Return value}
291
292 The string containing the current working directory or an empty string on
293 error.
294
295 \wxheading{See also}
296
297 \helpref{AssignCwd}{wxfilenameassigncwd}
298
299 \membersection{wxFileName::GetDirCount}\label{wxfilenamegetdircount}
300
301 \constfunc{size\_t}{GetDirCount}{\void}
302
303
304 \membersection{wxFileName::GetDirs}\label{wxfilenamegetdirs}
305
306 \constfunc{const wxArrayString\&}{GetDirs}{\void}
307
308
309 \membersection{wxFileName::GetExt}\label{wxfilenamegetext}
310
311 \constfunc{wxString}{GetExt}{\void}
312
313
314 \membersection{wxFileName::GetFormat}\label{wxfilenamegetformat}
315
316 \func{wxPathFormat}{GetFormat}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
317
318 various helpers
319 get the canonical path format for this platform
320
321
322 \membersection{wxFileName::GetFullName}\label{wxfilenamegetfullname}
323
324 \constfunc{wxString}{GetFullName}{\void}
325
326
327 \membersection{wxFileName::GetFullPath}\label{wxfilenamegetfullpath}
328
329 \constfunc{wxString}{GetFullPath}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
330
331 add separator Construct full path with name and ext
332
333
334 \membersection{wxFileName::GetHomeDir}\label{wxfilenamegethomedir}
335
336 \func{wxString}{GetHomeDir}{\void}
337
338
339 \membersection{wxFileName::GetLongPath}\label{wxfilenamegetlongpath}
340
341 \constfunc{wxString}{GetLongPath}{\void}
342
343 Return the long form of the path (returns identity on non-Windows platforms)
344
345
346 \membersection{wxFileName::GetModificationTime}\label{wxfilenamegetmodificationtime}
347
348 \constfunc{wxDateTime}{GetModificationTime}{\void}
349
350 convenience wrapper: get just the last mod time of the file
351
352
353 \membersection{wxFileName::GetName}\label{wxfilenamegetname}
354
355 \constfunc{wxString}{GetName}{\void}
356
357
358 \membersection{wxFileName::GetPath}\label{wxfilenamegetpath}
359
360 \constfunc{wxString}{GetPath}{\param{bool }{add\_separator = FALSE}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
361
362 Construct path only - possibly with the trailing separator
363
364
365 \membersection{wxFileName::GetPathSeparators}\label{wxfilenamegetpathseparators}
366
367 \func{wxString}{GetPathSeparators}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
368
369 get the string of path separators for this format
370
371
372 \membersection{wxFileName::GetPathWithSep}\label{wxfilenamegetpathwithsep}
373
374 \constfunc{wxString}{GetPathWithSep}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
375
376 more readable synonym
377
378
379 \membersection{wxFileName::GetShortPath}\label{wxfilenamegetshortpath}
380
381 \constfunc{wxString}{GetShortPath}{\void}
382
383 Return the short form of the path (returns identity on non-Windows platforms)
384
385
386 \membersection{wxFileName::GetTimes}\label{wxfilenamegettimes}
387
388 \constfunc{bool}{GetTimes}{\param{wxDateTime* }{dtAccess}, \param{wxDateTime* }{dtMod}, \param{wxDateTime* }{dtChange}}
389
390 return the last access, last modification and last change times
391 (any of the pointers may be NULL)
392
393
394 \membersection{wxFileName::GetVolume}\label{wxfilenamegetvolume}
395
396 \constfunc{wxString}{GetVolume}{\void}
397
398
399 \membersection{wxFileName::GetVolumeSeparator}\label{wxfilenamegetvolumeseparator}
400
401 \func{wxString}{GetVolumeSeparator}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
402
403 get the string separating the volume from the path for this format
404
405
406 \membersection{wxFileName::HasExt}\label{wxfilenamehasext}
407
408 \constfunc{bool}{HasExt}{\void}
409
410
411 \membersection{wxFileName::HasName}\label{wxfilenamehasname}
412
413 \constfunc{bool}{HasName}{\void}
414
415
416 \membersection{wxFileName::HasVolume}\label{wxfilenamehasvolume}
417
418 \constfunc{bool}{HasVolume}{\void}
419
420
421 \membersection{wxFileName::InsertDir}\label{wxfilenameinsertdir}
422
423 \func{void}{InsertDir}{\param{int }{before}, \param{const wxString\& }{dir}}
424
425
426 \membersection{wxFileName::IsAbsolute}\label{wxfilenameisabsolute}
427
428 \func{bool}{IsAbsolute}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
429
430 is this filename absolute?
431
432
433 \membersection{wxFileName::IsCaseSensitive}\label{wxfilenameiscasesensitive}
434
435 \func{bool}{IsCaseSensitive}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
436
437 Tests
438 are the file names of this type cases sensitive?
439
440
441 \membersection{wxFileName::IsOk}\label{wxfilenameisok}
442
443 \constfunc{bool}{IsOk}{\void}
444
445 Returns {\tt TRUE} if the filename is valid, {\tt FALSE} if it is not
446 initialized yet. The assignment functions and
447 \helpref{Clear}{wxfilenameclear} may reset the object to the uninitialized,
448 invalid state (the former only do it on failure).
449
450 \membersection{wxFileName::IsPathSeparator}\label{wxfilenameispathseparator}
451
452 \func{bool}{IsPathSeparator}{\param{wxChar }{ch}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
453
454 is the char a path separator for this format?
455
456
457 \membersection{wxFileName::IsRelative}\label{wxfilenameisrelative}
458
459 \func{bool}{IsRelative}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
460
461 is this filename relative?
462
463
464 \membersection{wxFileName::IsWild}\label{wxfilenameiswild}
465
466 \func{bool}{IsWild}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
467
468 FIXME: what exactly does this do?
469
470
471 \membersection{wxFileName::Mkdir}\label{wxfilenamemkdir}
472
473 \func{bool}{Mkdir}{\param{int }{perm = 0777}, \param{bool }{full = FALSE}}
474
475 \func{static bool}{Mkdir}{\param{const wxString\& }{dir}, \param{int }{perm = 0777}, \param{bool }{full = FALSE}}
476
477 \docparam{dir}{the directory to create}
478
479 \docparam{parm}{the permissions for the newly created directory}
480
481 \docparam{full}{if {\tt TRUE}, will try to make each directory in the path}
482
483 \wxheading{Return value}
484
485 Returns {\tt TRUE} if the directory was successfully created, {\tt FALSE}
486 otherwise.
487
488 \membersection{wxFileName::Normalize}\label{wxfilenamenormalize}
489
490 \func{bool}{Normalize}{\param{wxPathNormalize }{flags = wxPATH\_NORM\_ALL}, \param{const wxString\& }{cwd = wxEmptyString}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
491
492 operations on the path
493 normalize the path: with the default flags value, the path will be
494 made absolute, without any ".." and "." and all environment
495 variables will be expanded in it
496 this may be done using another (than current) value of cwd
497
498
499 \membersection{wxFileName::PrependDir}\label{wxfilenameprependdir}
500
501 \func{void}{PrependDir}{\param{const wxString\& }{dir}}
502
503
504 \membersection{wxFileName::RemoveDir}\label{wxfilenameremovedir}
505
506 \func{void}{RemoveDir}{\param{int }{pos}}
507
508
509 \membersection{wxFileName::Rmdir}\label{wxfilenamermdir}
510
511 \func{bool}{Rmdir}{\void}
512
513 \func{static bool}{Rmdir}{\param{const wxString\& }{dir}}
514
515 Deletes the specified directory.
516
517
518 \membersection{wxFileName::SameAs}\label{wxfilenamesameas}
519
520 \func{bool}{SameAs}{\param{const wxFileName\& }{filepath}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
521
522 Compares the filename using the rules of this platform
523
524
525 \membersection{wxFileName::SetCwd}\label{wxfilenamesetcwd}
526
527 \func{bool}{SetCwd}{\void}
528
529 \func{static bool}{SetCwd}{\param{const wxString\& }{cwd}}
530
531 change the current working directory
532
533 \membersection{wxFileName::SetExt}\label{wxfilenamesetext}
534
535 \func{void}{SetExt}{\param{const wxString\& }{ext}}
536
537
538 \membersection{wxFileName::SetFullName}\label{wxfilenamesetfullname}
539
540 \func{void}{SetFullName}{\param{const wxString\& }{fullname}}
541
542 full name is the file name + extension (but without the path)
543
544
545 \membersection{wxFileName::SetName}\label{wxfilenamesetname}
546
547 \func{void}{SetName}{\param{const wxString\& }{name}}
548
549
550 \membersection{wxFileName::SetTimes}\label{wxfilenamesettimes}
551
552 \func{bool}{SetTimes}{\param{const wxDateTime* }{dtCreate}, \param{const wxDateTime* }{dtAccess}, \param{const wxDateTime* }{dtMod}}
553
554 set the file creation and last access/mod times
555 (any of the pointers may be NULL)
556
557
558 \membersection{wxFileName::SetVolume}\label{wxfilenamesetvolume}
559
560 \func{void}{SetVolume}{\param{const wxString\& }{volume}}
561
562
563 \membersection{wxFileName::SplitPath}\label{wxfilenamesplitpath}
564
565 \func{void}{SplitPath}{\param{const wxString\& }{fullpath}, \param{wxString* }{volume}, \param{wxString* }{path}, \param{wxString* }{name}, \param{wxString* }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
566
567 \func{void}{SplitPath}{\param{const wxString\& }{fullpath}, \param{wxString* }{path}, \param{wxString* }{name}, \param{wxString* }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
568
569 split a fullpath into the volume, path, (base) name and extension
570 (all of the pointers can be NULL)
571
572 \membersection{wxFileName::Touch}\label{wxfilenametouch}
573
574 \func{bool}{Touch}{\void}
575
576 set the access and modification times to the current moment
577
578
579 \membersection{wxFileName::operator=}\label{wxfilenameoperatorassign}
580
581 \func{wxFileName\& operator}{operator=}{\param{const wxFileName\& }{filename}}
582
583 \func{wxFileName\& operator}{operator=}{\param{const wxString\& }{filename}}
584
585 Assigns the new value to this filename object.
586
587 \membersection{wxFileName::operator==}\label{wxfilenameoperatorequal}
588
589 \func{bool operator}{operator==}{\param{const wxFileName\& }{filename}}
590
591 \func{bool operator}{operator==}{\param{const wxString\& }{filename}}
592
593 Returns {\tt TRUE} if the filenames are equal for the native file format.
594