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