]>
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 licence
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
33 Constructs the object calling the Add() function.
35 wxPathList(const wxArrayString
& arr
);
38 Adds the given directory to the path list, if the @a path is not already in the list.
39 If the path cannot be normalized for some reason, it returns @false.
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).
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).
48 bool Add(const wxString
& path
);
51 Adds all elements of the given array as paths.
53 void Add(const wxArrayString
& arr
);
56 Finds the value of the given environment variable, and adds all paths
59 Useful for finding files in the @c PATH variable, for example.
61 void AddEnvList(const wxString
& env_variable
);
64 Given a full filename (with path), calls Add() with the path of the file.
66 bool EnsureFileAccessible(const wxString
& filename
);
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.
73 wxString
FindAbsoluteValidPath(const wxString
& file
) const;
76 Searches the given file in all paths stored in this class.
78 The first path which concatenated to the given string points to an existing
79 file (see wxFileExists()) is returned.
81 If the file wasn't found in any of the stored paths, an empty string is returned.
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
85 a directory separator (see wxFileName::GetPathSeparator) otherwise an assertion
88 The returned path may be relative to the current working directory.
90 Note in fact that wxPathList can be used to store both relative and absolute
91 paths so that if you added relative paths, then the current working directory
92 (see wxGetCwd() and wxSetWorkingDirectory()) may affect the value returned
95 wxString
FindValidPath(const wxString
& file
) const;
100 // ============================================================================
101 // Global functions/macros
102 // ============================================================================
104 /** @addtogroup group_funcmacro_file */
108 A special return value of many wxWidgets classes to indicate that
109 an invalid offset was given.
111 const int wxInvalidOffset
= -1;
114 The type used to store and provide byte offsets or byte sizes for files or streams.
116 It is type-defined as @c off_t on POSIX platforms
117 (see http://www.gnu.org/software/libc/manual/html_node/File-Position-Primitive.html)
118 or to @c wxLongLong_t on Windows when @c wxHAS_HUGE_FILES is defined.
120 typedef off_t wxFileOffset
;
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.
131 #define wxCHANGE_UMASK(mask)
134 This function returns the total number of bytes and number of free bytes on
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
141 @note The generic Unix implementation depends on the system having the
142 @c statfs() or @c statvfs() function.
144 @return @true on success, @false if an error occurred (for example, the
145 directory doesn’t exist).
149 bool wxGetDiskSpace(const wxString
& path
,
150 wxLongLong total
= NULL
,
151 wxLongLong free
= NULL
);
154 Returns the Windows directory under Windows; other platforms return an
159 wxString
wxGetOSDirectory();
162 Parses the @a wildCard, returning the number of filters. Returns 0 if none
163 or if there's a problem.
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:
170 "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
175 int wxParseCommonDialogsFilter(const wxString
& wildCard
,
176 wxArrayString
& descriptions
,
177 wxArrayString
& filters
);
180 Converts a DOS to a Unix filename by replacing backslashes with forward
184 Construct a wxFileName with wxPATH_DOS and then use
185 wxFileName::GetFullPath(wxPATH_UNIX) instead.
189 void wxDos2UnixFilename(wxChar
* s
);
192 Converts a Unix to a DOS filename by replacing forward slashes with
196 Construct a wxFileName with wxPATH_UNIX and then use
197 wxFileName::GetFullPath(wxPATH_DOS) instead.
201 void wxUnix2DosFilename(wxChar
* s
);
204 Returns @true if @a dirname exists and is a directory.
208 bool wxDirExists(const wxString
& dirname
);
212 This function is obsolete, please use wxFileName::SplitPath() instead.
214 This function splits a full file name into components: the path (including
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.
219 wxSplitPath() will correctly handle filenames with both DOS and Unix path
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).
223 On entry, @a fullname should be non-@NULL (it may be empty though).
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).
233 void wxSplitPath(const wxString
& fullname
,
239 Returns time of last modification of given file.
241 The function returns <tt>(time_t)-1</tt> if an error occurred (e.g. file
246 time_t wxFileModificationTime(const wxString
& filename
);
249 Renames @a file1 to @e file2, returning @true if successful.
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
258 bool wxRenameFile(const wxString
& file1
,
259 const wxString
& file2
,
260 bool overwrite
= true);
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.
267 This function supports resources forks under Mac OS.
271 bool wxCopyFile(const wxString
& file1
,
272 const wxString
& file2
,
273 bool overwrite
= true);
276 Returns @true if the file exists and is a plain file.
280 bool wxFileExists(const wxString
& filename
);
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
291 bool wxMatchWild(const wxString
& pattern
,
292 const wxString
& text
,
296 @deprecated This function is deprecated, use wxGetCwd() instead.
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
302 @a sz is the size of the buffer if supplied.
306 wxString
wxGetWorkingDirectory(char* buf
= NULL
, int sz
= 1000);
309 Returns the directory part of the filename.
313 wxString
wxPathOnly(const wxString
& path
);
316 Returns @true if the pattern contains wildcards.
322 bool wxIsWild(const wxString
& pattern
);
325 Returns @true if the argument is an absolute filename, i.e. with a slash
326 or drive name at the beginning.
330 bool wxIsAbsolutePath(const wxString
& filename
);
333 Returns a string containing the current (or working) directory.
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.
346 bool wxSetWorkingDirectory(const wxString
& dir
);
349 Concatenates @a file1 and @a file2 to @e file3, returning @true if
354 bool wxConcatFiles(const wxString
& file1
,
355 const wxString
& file2
,
356 const wxString
& file3
);
359 Removes @e file, returning @true if successful.
363 bool wxRemoveFile(const wxString
& file
);
366 File permission bit names.
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.
371 enum wxPosixPermissions
373 /// Standard POSIX names for these permission flags with "wx" prefix.
388 /// Longer but more readable synonyms for the constants above.
390 wxPOSIX_USER_READ
= wxS_IRUSR
,
391 wxPOSIX_USER_WRITE
= wxS_IWUSR
,
392 wxPOSIX_USER_EXECUTE
= wxS_IXUSR
,
394 wxPOSIX_GROUP_READ
= wxS_IRGRP
,
395 wxPOSIX_GROUP_WRITE
= wxS_IWGRP
,
396 wxPOSIX_GROUP_EXECUTE
= wxS_IXGRP
,
398 wxPOSIX_OTHERS_READ
= wxS_IROTH
,
399 wxPOSIX_OTHERS_WRITE
= wxS_IWOTH
,
400 wxPOSIX_OTHERS_EXECUTE
= wxS_IXOTH
,
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
),
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
)
419 Makes the directory @a dir, returning @true if successful.
421 @a perm is the access mask for the directory for the systems on which it is
422 supported (Unix) and doesn't have any effect on the other ones.
426 bool wxMkdir(const wxString
& dir
, int perm
= wxS_DIR_DEFAULT
);
429 Removes the directory @a dir, returning @true if successful. Does not work
432 The @a flags parameter is reserved for future use.
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.
441 bool wxRmdir(const wxString
& dir
, int flags
= 0);
444 Returns the next file that matches the path passed to wxFindFirstFile().
446 See wxFindFirstFile() for an example.
450 wxString
wxFindNextFile();
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
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.
462 @a spec may contain wildcards.
464 @a flags may be wxDIR for restricting the query to directories, wxFILE for
465 files or zero for either.
470 wxString f = wxFindFirstFile("/home/project/*.*");
474 f = wxFindNextFile();
480 wxString
wxFindFirstFile(const wxString
& spec
, int flags
= 0);
483 File kind enumerations returned from wxGetFileKind().
489 wxFILE_KIND_UNKNOWN
, ///< Unknown file kind, or unable to determine
490 wxFILE_KIND_DISK
, ///< A file supporting seeking to arbitrary offsets
491 wxFILE_KIND_TERMINAL
, ///< A tty
492 wxFILE_KIND_PIPE
///< A pipe
497 /** @addtogroup group_funcmacro_file */
500 Returns the type of an open file. Possible return values are enumerations
505 wxFileKind
wxGetFileKind(int fd
);
506 wxFileKind
wxGetFileKind(FILE* fp
);
509 /** @addtogroup group_funcmacro_file */
513 This function is obsolete, please use wxFileName::SplitPath() instead.
515 Returns the filename for a full path. The second form returns a pointer to
516 temporary storage that should not be deallocated.
520 wxString
wxFileNameFromPath(const wxString
& path
);
521 char* wxFileNameFromPath(char* path
);
524 /** @addtogroup group_funcmacro_file */
528 This function is obsolete, please use wxFileName::CreateTempFileName() instead.
532 char* wxGetTempFileName(const wxString
& prefix
, char* buf
= NULL
);
533 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
);