]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/filefn.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPathList and file functions
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 The path list is a convenient way of storing a number of directories, and
13 when presented with a filename without a directory, searching for an
14 existing file in those directories.
16 Be sure to look also at wxStandardPaths if you only want to search files in
22 @see wxArrayString, wxStandardPaths, wxFileName
24 class wxPathList
: public wxArrayString
30 Constructs the object calling the Add() function.
32 wxPathList(const wxArrayString
& arr
);
35 Adds the given directory to the path list, if the @a path is not already in the list.
36 If the path cannot be normalized for some reason, it returns @false.
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).
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).
45 bool Add(const wxString
& path
);
48 Adds all elements of the given array as paths.
50 void Add(const wxArrayString
& arr
);
53 Finds the value of the given environment variable, and adds all paths
56 Useful for finding files in the @c PATH variable, for example.
58 void AddEnvList(const wxString
& env_variable
);
61 Given a full filename (with path), calls Add() with the path of the file.
63 bool EnsureFileAccessible(const wxString
& filename
);
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.
70 wxString
FindAbsoluteValidPath(const wxString
& file
) const;
73 Searches the given file in all paths stored in this class.
75 The first path which concatenated to the given string points to an existing
76 file (see wxFileExists()) is returned.
78 If the file wasn't found in any of the stored paths, an empty string is returned.
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
82 a directory separator (see wxFileName::GetPathSeparator) otherwise an assertion
85 The returned path may be relative to the current working directory.
87 Note in fact that wxPathList can be used to store both relative and absolute
88 paths so that if you added relative paths, then the current working directory
89 (see wxGetCwd() and wxSetWorkingDirectory()) may affect the value returned
92 wxString
FindValidPath(const wxString
& file
) const;
97 // ============================================================================
98 // Global functions/macros
99 // ============================================================================
101 /** @ingroup group_funcmacro_file */
105 A special return value of many wxWidgets classes to indicate that
106 an invalid offset was given.
108 const int wxInvalidOffset
= -1;
111 Under Unix this macro changes the current process umask to the given value,
112 unless it is equal to -1 in which case nothing is done, and restores it to
113 the original value on scope exit. It works by declaring a variable which
114 sets umask to @a mask in its constructor and restores it in its destructor.
115 Under other platforms this macro expands to nothing.
119 #define wxCHANGE_UMASK(int mask)
122 This function returns the total number of bytes and number of free bytes on
123 the disk containing the directory @a path (it should exist). Both @a total
124 and @a free parameters may be @NULL if the corresponding information is not
129 @note The generic Unix implementation depends on the system having the
130 @c statfs() or @c statvfs() function.
132 @return @true on success, @false if an error occurred (for example, the
133 directory doesn’t exist).
137 bool wxGetDiskSpace(const wxString
& path
,
138 wxLongLong total
= NULL
,
139 wxLongLong free
= NULL
);
142 Returns the Windows directory under Windows; other platforms return an
147 wxString
wxGetOSDirectory();
150 Parses the @a wildCard, returning the number of filters. Returns 0 if none
151 or if there's a problem.
153 The arrays will contain an equal number of items found before the error. On
154 platforms where native dialogs handle only one filter per entry, entries in
155 arrays are automatically adjusted. @a wildCard is in the form:
158 "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
163 int wxParseCommonDialogsFilter(const wxString
& wildCard
,
164 wxArrayString
& descriptions
,
165 wxArrayString
& filters
);
168 Converts a DOS to a Unix filename by replacing backslashes with forward
173 void wxDos2UnixFilename(wxChar
* s
);
176 @warning This function is deprecated, use wxFileName instead.
178 Converts a Unix to a DOS filename by replacing forward slashes with
183 void wxUnix2DosFilename(wxChar
* s
);
186 Returns @true if @a dirname exists and is a directory.
190 bool wxDirExists(const wxString
& dirname
);
193 @warning This function is obsolete, please use wxFileName::SplitPath()
196 This function splits a full file name into components: the path (including
197 possible disk/drive specification under Windows), the base name, and the
198 extension. Any of the output parameters (@a path, @a name or @a ext) may be
199 @NULL if you are not interested in the value of a particular component.
201 wxSplitPath() will correctly handle filenames with both DOS and Unix path
202 separators under Windows, however it will not consider backslashes as path
203 separators under Unix (where backslash is a valid character in a filename).
205 On entry, @a fullname should be non-@NULL (it may be empty though).
207 On return, @a path contains the file path (without the trailing separator),
208 @a name contains the file name and @c ext contains the file extension
209 without leading dot. All three of them may be empty if the corresponding
210 component is. The old contents of the strings pointed to by these
211 parameters will be overwritten in any case (if the pointers are not @NULL).
215 void wxSplitPath(const wxString
& fullname
,
221 Returns time of last modification of given file.
223 The function returns <tt>(time_t)-1</tt> if an error occurred (e.g. file
228 time_t wxFileModificationTime(const wxString
& filename
);
231 Renames @a file1 to @e file2, returning @true if successful.
233 If @a overwrite parameter is @true (default), the destination file is
234 overwritten if it exists, but if @a overwrite is @false, the functions
239 bool wxRenameFile(const wxString
& file1
,
240 const wxString
& file2
,
241 bool overwrite
= true);
244 Copies @a file1 to @e file2, returning @true if successful. If @a overwrite
245 parameter is @true (default), the destination file is overwritten if it
246 exists, but if @a overwrite is @false, the functions fails in this case.
248 This function supports resources forks under Mac OS.
252 bool wxCopyFile(const wxString
& file1
,
253 const wxString
& file2
,
254 bool overwrite
= true);
257 Returns @true if the file exists and is a plain file.
261 bool wxFileExists(const wxString
& filename
);
264 Returns @true if the @a pattern matches the @e text; if @a dot_special is
265 @true, filenames beginning with a dot are not matched with wildcard
272 bool wxMatchWild(const wxString
& pattern
,
273 const wxString
& text
,
277 @warning This function is deprecated, use wxGetCwd() instead.
279 Copies the current working directory into the buffer if supplied, or copies
280 the working directory into new storage (which you must delete yourself) if
283 @a sz is the size of the buffer if supplied.
287 wxString
wxGetWorkingDirectory(char* buf
= NULL
, int sz
= 1000);
290 Returns the directory part of the filename.
294 wxString
wxPathOnly(const wxString
& path
);
297 Returns @true if the pattern contains wildcards.
303 bool wxIsWild(const wxString
& pattern
);
306 Returns @true if the argument is an absolute filename, i.e. with a slash
307 or drive name at the beginning.
311 bool wxIsAbsolutePath(const wxString
& filename
);
314 Returns a string containing the current (or working) directory.
321 Sets the current working directory, returning @true if the operation
322 succeeded. Under MS Windows, the current drive is also changed if @a dir
323 contains a drive specification.
327 bool wxSetWorkingDirectory(const wxString
& dir
);
330 Concatenates @a file1 and @a file2 to @e file3, returning @true if
335 bool wxConcatFiles(const wxString
& file1
,
336 const wxString
& file2
,
337 const wxString
& file3
);
340 Removes @e file, returning @true if successful.
344 bool wxRemoveFile(const wxString
& file
);
347 Makes the directory @a dir, returning @true if successful.
349 @a perm is the access mask for the directory for the systems on which it is
350 supported (Unix) and doesn't have any effect on the other ones.
354 bool wxMkdir(const wxString
& dir
, int perm
= 0777);
357 Removes the directory @a dir, returning @true if successful. Does not work
360 The @a flags parameter is reserved for future use.
362 @note There is also a wxRmDir() function which simply wraps the standard
363 POSIX @c rmdir() function and so return an integer error code instead
364 of a boolean value (but otherwise is currently identical to
365 wxRmdir()), don't confuse these two functions.
369 bool wxRmdir(const wxString
& dir
, int flags
= 0);
372 Returns the next file that matches the path passed to wxFindFirstFile().
374 See wxFindFirstFile() for an example.
378 wxString
wxFindNextFile();
381 This function does directory searching; returns the first file that matches
382 the path @a spec, or the empty string. Use wxFindNextFile() to get the next
383 matching file. Neither will report the current directory "." or the parent
386 @warning As of 2.5.2, these functions are not thread-safe! (they use static
387 variables). You probably want to use wxDir::GetFirst() or
388 wxDirTraverser instead.
390 @a spec may contain wildcards.
392 @a flags may be wxDIR for restricting the query to directories, wxFILE for
393 files or zero for either.
398 wxString f = wxFindFirstFile("/home/project/*.*");
402 f = wxFindNextFile();
408 wxString
wxFindFirstFile(const wxString
& spec
, int flags
= 0);
411 File kind enumerations returned from wxGetFileKind().
417 wxFILE_KIND_UNKNOWN
, ///< Unknown file kind, or unable to determine
418 wxFILE_KIND_DISK
, ///< A file supporting seeking to arbitrary offsets
419 wxFILE_KIND_TERMINAL
, ///< A tty
420 wxFILE_KIND_PIPE
///< A pipe
425 /** @ingroup group_funcmacro_file */
428 Returns the type of an open file. Possible return values are enumerations
433 wxFileKind
wxGetFileKind(int fd
);
434 wxFileKind
wxGetFileKind(FILE* fp
);
437 /** @ingroup group_funcmacro_file */
440 @warning This function is obsolete, please use wxFileName::SplitPath()
443 Returns the filename for a full path. The second form returns a pointer to
444 temporary storage that should not be deallocated.
448 wxString
wxFileNameFromPath(const wxString
& path
);
449 char* wxFileNameFromPath(char* path
);
452 /** @ingroup group_funcmacro_file */
455 @warning This function is obsolete, please use
456 wxFileName::CreateTempFileName() instead.
460 char* wxGetTempFileName(const wxString
& prefix
, char* buf
= NULL
);
461 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
);