These functions provide a platform-independent API for common file and directory functionality.
Related class group: File Handling
Defines | |
#define | wxCHANGE_UMASK(mask) |
Under Unix this macro changes the current process umask to the given value, unless it is equal to -1 in which case nothing is done, and restores it to the original value on scope exit. | |
Typedefs | |
typedef off_t | wxFileOffset |
The type used to store and provide byte offsets or byte sizes for files or streams. | |
Enumerations | |
enum | wxFileKind { wxFILE_KIND_UNKNOWN, wxFILE_KIND_DISK, wxFILE_KIND_TERMINAL, wxFILE_KIND_PIPE, wxFILE_KIND_UNKNOWN, wxFILE_KIND_DISK, wxFILE_KIND_TERMINAL, wxFILE_KIND_PIPE } |
File kind enumerations returned from wxGetFileKind(). More... | |
Functions | |
bool | wxTransferFileToStream (const wxString &filename, ostream &stream) |
Copies the given file to stream. | |
bool | wxTransferStreamToFile (istream &stream, const wxString &filename) |
Copies the given stream to the file filename. | |
bool | wxGetDiskSpace (const wxString &path, wxLongLong total=NULL, wxLongLong free=NULL) |
This function returns the total number of bytes and number of free bytes on the disk containing the directory path (it should exist). | |
wxString | wxGetOSDirectory () |
Returns the Windows directory under Windows; other platforms return an empty string. | |
int | wxParseCommonDialogsFilter (const wxString &wildCard, wxArrayString &descriptions, wxArrayString &filters) |
Parses the wildCard, returning the number of filters. | |
void | wxDos2UnixFilename (wxChar *s) |
Converts a DOS to a Unix filename by replacing backslashes with forward slashes. | |
void | wxUnix2DosFilename (wxChar *s) |
Converts a Unix to a DOS filename by replacing forward slashes with backslashes. | |
bool | wxDirExists (const wxString &dirname) |
Returns true if dirname exists and is a directory. | |
void | wxSplitPath (const wxString &fullname, wxString *path, wxString *name, wxString *ext) |
time_t | wxFileModificationTime (const wxString &filename) |
Returns time of last modification of given file. | |
bool | wxRenameFile (const wxString &file1, const wxString &file2, bool overwrite=true) |
Renames file1 to file2, returning true if successful. | |
bool | wxCopyFile (const wxString &file1, const wxString &file2, bool overwrite=true) |
Copies file1 to file2, returning true if successful. | |
bool | wxFileExists (const wxString &filename) |
Returns true if the file exists and is a plain file. | |
bool | wxMatchWild (const wxString &pattern, const wxString &text, bool dot_special) |
Returns true if the pattern matches the text; if dot_special is true, filenames beginning with a dot are not matched with wildcard characters. | |
wxString | wxGetWorkingDirectory (char *buf=NULL, int sz=1000) |
wxString | wxPathOnly (const wxString &path) |
Returns the directory part of the filename. | |
bool | wxIsWild (const wxString &pattern) |
Returns true if the pattern contains wildcards. | |
bool | wxIsAbsolutePath (const wxString &filename) |
Returns true if the argument is an absolute filename, i.e. | |
wxString | wxGetCwd () |
Returns a string containing the current (or working) directory. | |
bool | wxSetWorkingDirectory (const wxString &dir) |
Sets the current working directory, returning true if the operation succeeded. | |
bool | wxConcatFiles (const wxString &file1, const wxString &file2, const wxString &file3) |
Concatenates file1 and file2 to file3, returning true if successful. | |
bool | wxRemoveFile (const wxString &file) |
Removes file, returning true if successful. | |
bool | wxMkdir (const wxString &dir, int perm=0777) |
Makes the directory dir, returning true if successful. | |
bool | wxRmdir (const wxString &dir, int flags=0) |
Removes the directory dir, returning true if successful. | |
wxString | wxFindNextFile () |
Returns the next file that matches the path passed to wxFindFirstFile(). | |
wxString | wxFindFirstFile (const wxString &spec, int flags=0) |
This function does directory searching; returns the first file that matches the path spec, or the empty string. | |
wxFileKind | wxGetFileKind (int fd) |
Returns the type of an open file. | |
wxFileKind | wxGetFileKind (FILE *fp) |
wxString | wxFileNameFromPath (const wxString &path) |
char * | wxFileNameFromPath (char *path) |
char * | wxGetTempFileName (const wxString &prefix, char *buf=NULL) |
bool | wxGetTempFileName (const wxString &prefix, wxString &buf) |
Variables | |
const int | wxInvalidOffset = -1 |
A special return value of many wxWidgets classes to indicate that an invalid offset was given. |
#define wxCHANGE_UMASK | ( | mask | ) |
Under Unix this macro changes the current process umask to the given value, unless it is equal to -1 in which case nothing is done, and restores it to the original value on scope exit.
It works by declaring a variable which sets umask to mask in its constructor and restores it in its destructor. Under other platforms this macro expands to nothing.
Include file:
#include <wx/filefn.h>
typedef off_t wxFileOffset |
The type used to store and provide byte offsets or byte sizes for files or streams.
It is type-defined as off_t
on POSIX platforms (see http://www.gnu.org/software/libc/manual/html_node/File-Position-Primitive.html) or to wxLongLong_t
on Windows when wxHAS_HUGE_FILES
is defined.
enum wxFileKind |
File kind enumerations returned from wxGetFileKind().
Include file:
#include <wx/filefn.h>
Concatenates file1 and file2 to file3, returning true if successful.
Include file:
#include <wx/filefn.h>
Copies file1 to file2, returning true if successful.
If overwrite parameter is true (default), the destination file is overwritten if it exists, but if overwrite is false, the functions fails in this case.
This function supports resources forks under Mac OS.
Include file:
#include <wx/filefn.h>
bool wxDirExists | ( | const wxString & | dirname | ) |
Returns true if dirname exists and is a directory.
Include file:
#include <wx/filefn.h>
void wxDos2UnixFilename | ( | wxChar * | s | ) |
Converts a DOS to a Unix filename by replacing backslashes with forward slashes.
Include file:
#include <wx/filefn.h>
bool wxFileExists | ( | const wxString & | filename | ) |
Returns true if the file exists and is a plain file.
Include file:
#include <wx/filefn.h>
time_t wxFileModificationTime | ( | const wxString & | filename | ) |
Returns time of last modification of given file.
The function returns (time_t)-1
if an error occurred (e.g. file not found).
Include file:
#include <wx/filefn.h>
char* wxFileNameFromPath | ( | char * | path | ) |
Returns the filename for a full path. The second form returns a pointer to temporary storage that should not be deallocated.
Include file:
#include <wx/filefn.h>
This function does directory searching; returns the first file that matches the path spec, or the empty string.
Use wxFindNextFile() to get the next matching file. Neither will report the current directory "." or the parent directory "..".
spec may contain wildcards.
flags may be wxDIR for restricting the query to directories, wxFILE for files or zero for either.
For example:
wxString f = wxFindFirstFile("/home/project/*.*"); while ( !f.empty() ) { ... f = wxFindNextFile(); }
Include file:
#include <wx/filefn.h>
wxString wxFindNextFile | ( | ) |
Returns the next file that matches the path passed to wxFindFirstFile().
See wxFindFirstFile() for an example.
Include file:
#include <wx/filefn.h>
wxString wxGetCwd | ( | ) |
Returns a string containing the current (or working) directory.
Include file:
#include <wx/filefn.h>
bool wxGetDiskSpace | ( | const wxString & | path, | |
wxLongLong | total = NULL , |
|||
wxLongLong | free = NULL | |||
) |
This function returns the total number of bytes and number of free bytes on the disk containing the directory path (it should exist).
Both total and free parameters may be NULL if the corresponding information is not needed.
statfs()
or statvfs()
function.Include file:
#include <wx/filefn.h>
wxFileKind wxGetFileKind | ( | FILE * | fp | ) |
wxFileKind wxGetFileKind | ( | int | fd | ) |
Returns the type of an open file.
Possible return values are enumerations of wxFileKind.
Include file:
#include <wx/filefn.h>
wxString wxGetOSDirectory | ( | ) |
Returns the Windows directory under Windows; other platforms return an empty string.
Include file:
#include <wx/filefn.h>
char* wxGetTempFileName | ( | const wxString & | prefix, | |
char * | buf = NULL | |||
) |
Include file:
#include <wx/filefn.h>
wxString wxGetWorkingDirectory | ( | char * | buf = NULL , |
|
int | sz = 1000 | |||
) |
Copies the current working directory into the buffer if supplied, or copies the working directory into new storage (which you must delete yourself) if the buffer is NULL.
sz is the size of the buffer if supplied.
Include file:
#include <wx/filefn.h>
bool wxIsAbsolutePath | ( | const wxString & | filename | ) |
Returns true if the argument is an absolute filename, i.e.
with a slash or drive name at the beginning.
Include file:
#include <wx/filefn.h>
bool wxIsWild | ( | const wxString & | pattern | ) |
Returns true if the pattern contains wildcards.
Include file:
#include <wx/filefn.h>
Returns true if the pattern matches the text; if dot_special is true, filenames beginning with a dot are not matched with wildcard characters.
Include file:
#include <wx/filefn.h>
bool wxMkdir | ( | const wxString & | dir, | |
int | perm = 0777 | |||
) |
Makes the directory dir, returning true if successful.
perm is the access mask for the directory for the systems on which it is supported (Unix) and doesn't have any effect on the other ones.
Include file:
#include <wx/filefn.h>
int wxParseCommonDialogsFilter | ( | const wxString & | wildCard, | |
wxArrayString & | descriptions, | |||
wxArrayString & | filters | |||
) |
Parses the wildCard, returning the number of filters.
Returns 0 if none or if there's a problem.
The arrays will contain an equal number of items found before the error. On platforms where native dialogs handle only one filter per entry, entries in arrays are automatically adjusted. wildCard is in the form:
"All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
Include file:
#include <wx/filefn.h>
Returns the directory part of the filename.
Include file:
#include <wx/filefn.h>
bool wxRemoveFile | ( | const wxString & | file | ) |
Removes file, returning true if successful.
Include file:
#include <wx/filefn.h>
Renames file1 to file2, returning true if successful.
If overwrite parameter is true (default), the destination file is overwritten if it exists, but if overwrite is false, the functions fails in this case.
Include file:
#include <wx/filefn.h>
bool wxRmdir | ( | const wxString & | dir, | |
int | flags = 0 | |||
) |
Removes the directory dir, returning true if successful.
Does not work under VMS.
The flags parameter is reserved for future use.
rmdir()
function and so return an integer error code instead of a boolean value (but otherwise is currently identical to wxRmdir()), don't confuse these two functions.Include file:
#include <wx/filefn.h>
bool wxSetWorkingDirectory | ( | const wxString & | dir | ) |
Sets the current working directory, returning true if the operation succeeded.
Under MS Windows, the current drive is also changed if dir contains a drive specification.
Include file:
#include <wx/filefn.h>
This function splits a full file name into components: the path (including possible disk/drive specification under Windows), the base name, and the extension. Any of the output parameters (path, name or ext) may be NULL if you are not interested in the value of a particular component.
wxSplitPath() will correctly handle filenames with both DOS and Unix path separators under Windows, however it will not consider backslashes as path separators under Unix (where backslash is a valid character in a filename).
On entry, fullname should be non-NULL (it may be empty though).
On return, path contains the file path (without the trailing separator), name contains the file name and ext
contains the file extension without leading dot. All three of them may be empty if the corresponding component is. The old contents of the strings pointed to by these parameters will be overwritten in any case (if the pointers are not NULL).
Include file:
#include <wx/filefn.h>
bool wxTransferFileToStream | ( | const wxString & | filename, | |
ostream & | stream | |||
) |
Copies the given file to stream.
Useful when converting an old application to use streams (within the document/view framework, for example).
Include file:
#include <wx/docview.h>
bool wxTransferStreamToFile | ( | istream & | stream, | |
const wxString & | filename | |||
) |
Copies the given stream to the file filename.
Useful when converting an old application to use streams (within the document/view framework, for example).
Include file:
#include <wx/docview.h>
void wxUnix2DosFilename | ( | wxChar * | s | ) |
Converts a Unix to a DOS filename by replacing forward slashes with backslashes.
Include file:
#include <wx/filefn.h>
const int wxInvalidOffset = -1 |
A special return value of many wxWidgets classes to indicate that an invalid offset was given.
![]() |
[ top ] |