]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/filefn.h
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[wxWidgets.git] / interface / wx / filefn.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: filefn.h
1ba0de2e 3// Purpose: interface of wxPathList and file functions
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxPathList
7c913512 11
23324ae1 12 The path list is a convenient way of storing a number of directories, and
1ba0de2e
BP
13 when presented with a filename without a directory, searching for an
14 existing file in those directories.
7c913512 15
1ba0de2e
BP
16 Be sure to look also at wxStandardPaths if you only want to search files in
17 some standard paths.
7c913512 18
23324ae1
FM
19 @library{wxbase}
20 @category{file}
7c913512 21
e54c96f1 22 @see wxArrayString, wxStandardPaths, wxFileName
23324ae1
FM
23*/
24class wxPathList : public wxArrayString
25{
26public:
69fc8587
FM
27 /**
28 Standard constructor.
29 */
0ce6d6c8
FM
30 wxPathList();
31
23324ae1
FM
32 /**
33 Constructs the object calling the Add() function.
34 */
7c913512 35 wxPathList(const wxArrayString& arr);
23324ae1 36
23324ae1 37 /**
0ce6d6c8 38 Adds the given directory to the path list, if the @a path is not already in the list.
23324ae1 39 If the path cannot be normalized for some reason, it returns @false.
0ce6d6c8
FM
40
41 The @a path is always considered to be a directory but no existence checks will be
42 done on it (because if it doesn't exist, it could be created later and thus result a
43 valid path when FindValidPath() is called).
44
45 @note if the given path is relative, it won't be made absolute before adding it
46 (this is why FindValidPath() may return relative paths).
23324ae1
FM
47 */
48 bool Add(const wxString& path);
0ce6d6c8
FM
49
50 /**
51 Adds all elements of the given array as paths.
52 */
7c913512 53 void Add(const wxArrayString& arr);
23324ae1
FM
54
55 /**
56 Finds the value of the given environment variable, and adds all paths
0ce6d6c8
FM
57 to the path list.
58
59 Useful for finding files in the @c PATH variable, for example.
23324ae1
FM
60 */
61 void AddEnvList(const wxString& env_variable);
62
63 /**
0ce6d6c8 64 Given a full filename (with path), calls Add() with the path of the file.
23324ae1
FM
65 */
66 bool EnsureFileAccessible(const wxString& filename);
67
68 /**
0ce6d6c8
FM
69 Like FindValidPath() but this function always returns an absolute path
70 (eventually prepending the current working directory to the value returned
71 wxPathList::FindValidPath()) or an empty string.
23324ae1 72 */
328f5751 73 wxString FindAbsoluteValidPath(const wxString& file) const;
23324ae1
FM
74
75 /**
76 Searches the given file in all paths stored in this class.
0ce6d6c8 77
23324ae1 78 The first path which concatenated to the given string points to an existing
1ba0de2e 79 file (see wxFileExists()) is returned.
0ce6d6c8
FM
80
81 If the file wasn't found in any of the stored paths, an empty string is returned.
82
23324ae1
FM
83 The given string must be a file name, eventually with a path prefix (if the path
84 prefix is absolute, only its name will be searched); i.e. it must not end with
0ce6d6c8
FM
85 a directory separator (see wxFileName::GetPathSeparator) otherwise an assertion
86 will fail.
87
23324ae1 88 The returned path may be relative to the current working directory.
0ce6d6c8 89
23324ae1 90 Note in fact that wxPathList can be used to store both relative and absolute
0ce6d6c8
FM
91 paths so that if you added relative paths, then the current working directory
92 (see wxGetCwd() and wxSetWorkingDirectory()) may affect the value returned
93 by this function!
23324ae1 94 */
328f5751 95 wxString FindValidPath(const wxString& file) const;
23324ae1
FM
96};
97
98
e54c96f1 99
23324ae1
FM
100// ============================================================================
101// Global functions/macros
102// ============================================================================
103
b21126db 104/** @addtogroup group_funcmacro_file */
1ba0de2e
BP
105//@{
106
e7d0a28b
FM
107/**
108 A special return value of many wxWidgets classes to indicate that
109 an invalid offset was given.
110*/
111const int wxInvalidOffset = -1;
112
72dc02c6
FM
113/**
114 The type used to store and provide byte offsets or byte sizes for files or streams.
115
8bc6150f
VZ
116 This type is usually just a synonym for @c off_t but can be defined as
117 @c wxLongLong_t if @c wxHAS_HUGE_FILES is defined but @c off_t is only 32
118 bits.
72dc02c6
FM
119*/
120typedef off_t wxFileOffset;
121
1ba0de2e
BP
122/**
123 Under Unix this macro changes the current process umask to the given value,
124 unless it is equal to -1 in which case nothing is done, and restores it to
125 the original value on scope exit. It works by declaring a variable which
126 sets umask to @a mask in its constructor and restores it in its destructor.
127 Under other platforms this macro expands to nothing.
128
129 @header{wx/filefn.h}
130*/
d7b99b16 131#define wxCHANGE_UMASK(mask)
1ba0de2e 132
23324ae1
FM
133/**
134 This function returns the total number of bytes and number of free bytes on
1ba0de2e
BP
135 the disk containing the directory @a path (it should exist). Both @a total
136 and @a free parameters may be @NULL if the corresponding information is not
137 needed.
138
1e24c2af 139 @since 2.3.2
1ba0de2e
BP
140
141 @note The generic Unix implementation depends on the system having the
142 @c statfs() or @c statvfs() function.
143
d29a9a8a 144 @return @true on success, @false if an error occurred (for example, the
1ba0de2e
BP
145 directory doesn’t exist).
146
147 @header{wx/filefn.h}
23324ae1
FM
148*/
149bool wxGetDiskSpace(const wxString& path,
4cc4bfaf
FM
150 wxLongLong total = NULL,
151 wxLongLong free = NULL);
23324ae1
FM
152
153/**
1ba0de2e 154 Returns the Windows directory under Windows; other platforms return an
23324ae1 155 empty string.
1ba0de2e
BP
156
157 @header{wx/filefn.h}
23324ae1
FM
158*/
159wxString wxGetOSDirectory();
160
161/**
1ba0de2e
BP
162 Parses the @a wildCard, returning the number of filters. Returns 0 if none
163 or if there's a problem.
164
165 The arrays will contain an equal number of items found before the error. On
166 platforms where native dialogs handle only one filter per entry, entries in
167 arrays are automatically adjusted. @a wildCard is in the form:
7c913512 168
23324ae1
FM
169 @code
170 "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
171 @endcode
1ba0de2e
BP
172
173 @header{wx/filefn.h}
23324ae1
FM
174*/
175int wxParseCommonDialogsFilter(const wxString& wildCard,
176 wxArrayString& descriptions,
177 wxArrayString& filters);
178
179/**
1ba0de2e
BP
180 Converts a DOS to a Unix filename by replacing backslashes with forward
181 slashes.
182
47d281e6
FM
183 @deprecated
184 Construct a wxFileName with wxPATH_DOS and then use
185 wxFileName::GetFullPath(wxPATH_UNIX) instead.
186
1ba0de2e
BP
187 @header{wx/filefn.h}
188*/
189void wxDos2UnixFilename(wxChar* s);
190
191/**
1ba0de2e
BP
192 Converts a Unix to a DOS filename by replacing forward slashes with
193 backslashes.
194
47d281e6
FM
195 @deprecated
196 Construct a wxFileName with wxPATH_UNIX and then use
197 wxFileName::GetFullPath(wxPATH_DOS) instead.
198
1ba0de2e 199 @header{wx/filefn.h}
23324ae1 200*/
4cc4bfaf 201void wxUnix2DosFilename(wxChar* s);
23324ae1
FM
202
203/**
4cc4bfaf 204 Returns @true if @a dirname exists and is a directory.
1ba0de2e
BP
205
206 @header{wx/filefn.h}
23324ae1
FM
207*/
208bool wxDirExists(const wxString& dirname);
209
210/**
47d281e6
FM
211 @deprecated
212 This function is obsolete, please use wxFileName::SplitPath() instead.
1ba0de2e 213
23324ae1 214 This function splits a full file name into components: the path (including
1ba0de2e
BP
215 possible disk/drive specification under Windows), the base name, and the
216 extension. Any of the output parameters (@a path, @a name or @a ext) may be
217 @NULL if you are not interested in the value of a particular component.
218
23324ae1 219 wxSplitPath() will correctly handle filenames with both DOS and Unix path
1ba0de2e
BP
220 separators under Windows, however it will not consider backslashes as path
221 separators under Unix (where backslash is a valid character in a filename).
222
4cc4bfaf 223 On entry, @a fullname should be non-@NULL (it may be empty though).
23324ae1 224
1ba0de2e
BP
225 On return, @a path contains the file path (without the trailing separator),
226 @a name contains the file name and @c ext contains the file extension
227 without leading dot. All three of them may be empty if the corresponding
228 component is. The old contents of the strings pointed to by these
229 parameters will be overwritten in any case (if the pointers are not @NULL).
230
231 @header{wx/filefn.h}
23324ae1 232*/
1ba0de2e
BP
233void wxSplitPath(const wxString& fullname,
234 wxString* path,
235 wxString* name,
236 wxString* ext);
23324ae1
FM
237
238/**
239 Returns time of last modification of given file.
23324ae1 240
1ba0de2e
BP
241 The function returns <tt>(time_t)-1</tt> if an error occurred (e.g. file
242 not found).
243
244 @header{wx/filefn.h}
23324ae1 245*/
1ba0de2e 246time_t wxFileModificationTime(const wxString& filename);
23324ae1
FM
247
248/**
4cc4bfaf 249 Renames @a file1 to @e file2, returning @true if successful.
1ba0de2e 250
327ac3ec
VZ
251 If @a file2 is a directory, @a file1 is moved into it (@a overwrite is
252 ignored in this case). Otherwise, if @a file2 is an existing file, it is
253 overwritten if @a overwrite is @true (default) and the function fails if @a
254 overwrite is @false.
1ba0de2e
BP
255
256 @header{wx/filefn.h}
23324ae1 257*/
1ba0de2e
BP
258bool wxRenameFile(const wxString& file1,
259 const wxString& file2,
260 bool overwrite = true);
23324ae1
FM
261
262/**
1ba0de2e
BP
263 Copies @a file1 to @e file2, returning @true if successful. If @a overwrite
264 parameter is @true (default), the destination file is overwritten if it
265 exists, but if @a overwrite is @false, the functions fails in this case.
266
23324ae1 267 This function supports resources forks under Mac OS.
1ba0de2e
BP
268
269 @header{wx/filefn.h}
23324ae1 270*/
1ba0de2e
BP
271bool wxCopyFile(const wxString& file1,
272 const wxString& file2,
273 bool overwrite = true);
23324ae1
FM
274
275/**
276 Returns @true if the file exists and is a plain file.
1ba0de2e
BP
277
278 @header{wx/filefn.h}
23324ae1
FM
279*/
280bool wxFileExists(const wxString& filename);
281
282/**
1ba0de2e
BP
283 Returns @true if the @a pattern matches the @e text; if @a dot_special is
284 @true, filenames beginning with a dot are not matched with wildcard
285 characters.
286
287 @see wxIsWild()
288
289 @header{wx/filefn.h}
23324ae1 290*/
1ba0de2e
BP
291bool wxMatchWild(const wxString& pattern,
292 const wxString& text,
293 bool dot_special);
23324ae1
FM
294
295/**
47d281e6 296 @deprecated This function is deprecated, use wxGetCwd() instead.
1ba0de2e
BP
297
298 Copies the current working directory into the buffer if supplied, or copies
299 the working directory into new storage (which you must delete yourself) if
300 the buffer is @NULL.
301
4cc4bfaf 302 @a sz is the size of the buffer if supplied.
1ba0de2e
BP
303
304 @header{wx/filefn.h}
23324ae1 305*/
4cc4bfaf 306wxString wxGetWorkingDirectory(char* buf = NULL, int sz = 1000);
23324ae1
FM
307
308/**
309 Returns the directory part of the filename.
1ba0de2e
BP
310
311 @header{wx/filefn.h}
23324ae1
FM
312*/
313wxString wxPathOnly(const wxString& path);
314
315/**
1ba0de2e
BP
316 Returns @true if the pattern contains wildcards.
317
318 @see wxMatchWild()
319
320 @header{wx/filefn.h}
23324ae1
FM
321*/
322bool wxIsWild(const wxString& pattern);
323
1ba0de2e
BP
324/**
325 Returns @true if the argument is an absolute filename, i.e. with a slash
326 or drive name at the beginning.
327
328 @header{wx/filefn.h}
329*/
330bool wxIsAbsolutePath(const wxString& filename);
331
23324ae1
FM
332/**
333 Returns a string containing the current (or working) directory.
1ba0de2e
BP
334
335 @header{wx/filefn.h}
23324ae1
FM
336*/
337wxString wxGetCwd();
338
339/**
1ba0de2e
BP
340 Sets the current working directory, returning @true if the operation
341 succeeded. Under MS Windows, the current drive is also changed if @a dir
342 contains a drive specification.
343
344 @header{wx/filefn.h}
23324ae1 345*/
1ba0de2e 346bool wxSetWorkingDirectory(const wxString& dir);
23324ae1
FM
347
348/**
1ba0de2e
BP
349 Concatenates @a file1 and @a file2 to @e file3, returning @true if
350 successful.
351
352 @header{wx/filefn.h}
23324ae1 353*/
1ba0de2e
BP
354bool wxConcatFiles(const wxString& file1,
355 const wxString& file2,
356 const wxString& file3);
23324ae1
FM
357
358/**
359 Removes @e file, returning @true if successful.
1ba0de2e
BP
360
361 @header{wx/filefn.h}
23324ae1
FM
362*/
363bool wxRemoveFile(const wxString& file);
364
9508a23a
VZ
365/**
366 File permission bit names.
367
368 We define these constants in wxWidgets because S_IREAD &c are not standard.
369 However, we do assume that the values correspond to the Unix umask bits.
370*/
371enum wxPosixPermissions
372{
373 /// Standard POSIX names for these permission flags with "wx" prefix.
374 //@{
375 wxS_IRUSR = 00400,
376 wxS_IWUSR = 00200,
377 wxS_IXUSR = 00100,
378
379 wxS_IRGRP = 00040,
380 wxS_IWGRP = 00020,
381 wxS_IXGRP = 00010,
382
383 wxS_IROTH = 00004,
384 wxS_IWOTH = 00002,
385 wxS_IXOTH = 00001,
386 //@}
387
388 /// Longer but more readable synonyms for the constants above.
389 //@{
390 wxPOSIX_USER_READ = wxS_IRUSR,
391 wxPOSIX_USER_WRITE = wxS_IWUSR,
392 wxPOSIX_USER_EXECUTE = wxS_IXUSR,
393
394 wxPOSIX_GROUP_READ = wxS_IRGRP,
395 wxPOSIX_GROUP_WRITE = wxS_IWGRP,
396 wxPOSIX_GROUP_EXECUTE = wxS_IXGRP,
397
398 wxPOSIX_OTHERS_READ = wxS_IROTH,
399 wxPOSIX_OTHERS_WRITE = wxS_IWOTH,
400 wxPOSIX_OTHERS_EXECUTE = wxS_IXOTH,
401 //@}
402
403 /// Default mode for the new files: allow reading/writing them to everybody but
404 /// the effective file mode will be set after ANDing this value with umask and
405 /// so won't include wxS_IW{GRP,OTH} for the default 022 umask value
406 wxS_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | \
407 wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | \
408 wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE),
409
410 /// Default mode for the new directories (see wxFileName::Mkdir): allow
411 /// reading/writing/executing them to everybody, but just like wxS_DEFAULT
412 /// the effective directory mode will be set after ANDing this value with umask
413 wxS_DIR_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE | \
414 wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | wxPOSIX_GROUP_EXECUTE | \
415 wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE | wxPOSIX_OTHERS_EXECUTE)
416};
417
23324ae1 418/**
1ba0de2e 419 Makes the directory @a dir, returning @true if successful.
23324ae1 420
4cc4bfaf 421 @a perm is the access mask for the directory for the systems on which it is
23324ae1 422 supported (Unix) and doesn't have any effect on the other ones.
1ba0de2e
BP
423
424 @header{wx/filefn.h}
23324ae1 425*/
9508a23a 426bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
23324ae1
FM
427
428/**
1ba0de2e
BP
429 Removes the directory @a dir, returning @true if successful. Does not work
430 under VMS.
431
432 The @a flags parameter is reserved for future use.
433
434 @note There is also a wxRmDir() function which simply wraps the standard
435 POSIX @c rmdir() function and so return an integer error code instead
436 of a boolean value (but otherwise is currently identical to
437 wxRmdir()), don't confuse these two functions.
438
439 @header{wx/filefn.h}
23324ae1 440*/
1ba0de2e 441bool wxRmdir(const wxString& dir, int flags = 0);
23324ae1
FM
442
443/**
e54c96f1 444 Returns the next file that matches the path passed to wxFindFirstFile().
1ba0de2e 445
e54c96f1 446 See wxFindFirstFile() for an example.
1ba0de2e
BP
447
448 @header{wx/filefn.h}
23324ae1
FM
449*/
450wxString wxFindNextFile();
451
452/**
1ba0de2e
BP
453 This function does directory searching; returns the first file that matches
454 the path @a spec, or the empty string. Use wxFindNextFile() to get the next
455 matching file. Neither will report the current directory "." or the parent
456 directory "..".
457
458 @warning As of 2.5.2, these functions are not thread-safe! (they use static
459 variables). You probably want to use wxDir::GetFirst() or
460 wxDirTraverser instead.
461
462 @a spec may contain wildcards.
463
464 @a flags may be wxDIR for restricting the query to directories, wxFILE for
465 files or zero for either.
466
467 For example:
468
469 @code
470 wxString f = wxFindFirstFile("/home/project/*.*");
471 while ( !f.empty() )
472 {
473 ...
474 f = wxFindNextFile();
475 }
476 @endcode
477
478 @header{wx/filefn.h}
23324ae1
FM
479*/
480wxString wxFindFirstFile(const wxString& spec, int flags = 0);
481
bf973818
VZ
482/**
483 Parameter indicating how file offset should be interpreted.
484
485 This is used by wxFFile::Seek() and wxFile::Seek().
486
487 @header{wx/filefn.h}
488*/
489enum wxSeekMode
490{
491 wxFromStart, ///< Seek from the file beginning.
492 wxFromCurrent, ///< Seek from the current position.
493 wxFromEnd ///< Seek from end of the file.
494};
495
1ba0de2e
BP
496/**
497 File kind enumerations returned from wxGetFileKind().
498
bf973818
VZ
499 Also used by wxFFile::GetKind() and wxFile::GetKind().
500
1ba0de2e
BP
501 @header{wx/filefn.h}
502*/
503enum wxFileKind
504{
505 wxFILE_KIND_UNKNOWN, ///< Unknown file kind, or unable to determine
506 wxFILE_KIND_DISK, ///< A file supporting seeking to arbitrary offsets
507 wxFILE_KIND_TERMINAL, ///< A tty
508 wxFILE_KIND_PIPE ///< A pipe
509};
510
511//@}
512
b21126db 513/** @addtogroup group_funcmacro_file */
23324ae1
FM
514//@{
515/**
1ba0de2e
BP
516 Returns the type of an open file. Possible return values are enumerations
517 of ::wxFileKind.
4cc4bfaf 518
1ba0de2e 519 @header{wx/filefn.h}
23324ae1
FM
520*/
521wxFileKind wxGetFileKind(int fd);
4cc4bfaf 522wxFileKind wxGetFileKind(FILE* fp);
23324ae1
FM
523//@}
524
b21126db 525/** @addtogroup group_funcmacro_file */
23324ae1
FM
526//@{
527/**
47d281e6
FM
528 @deprecated
529 This function is obsolete, please use wxFileName::SplitPath() instead.
1ba0de2e
BP
530
531 Returns the filename for a full path. The second form returns a pointer to
532 temporary storage that should not be deallocated.
533
534 @header{wx/filefn.h}
23324ae1 535*/
1ba0de2e
BP
536wxString wxFileNameFromPath(const wxString& path);
537char* wxFileNameFromPath(char* path);
23324ae1
FM
538//@}
539
b21126db 540/** @addtogroup group_funcmacro_file */
1ba0de2e 541//@{
23324ae1 542/**
47d281e6
FM
543 @deprecated
544 This function is obsolete, please use wxFileName::CreateTempFileName() instead.
1ba0de2e
BP
545
546 @header{wx/filefn.h}
23324ae1 547*/
1ba0de2e
BP
548char* wxGetTempFileName(const wxString& prefix, char* buf = NULL);
549bool wxGetTempFileName(const wxString& prefix, wxString& buf);
550//@}
23324ae1 551