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 | wxPosixPermissions { wxS_IRUSR = 00400, wxS_IWUSR = 00200, wxS_IXUSR = 00100, wxS_IRGRP = 00040, wxS_IWGRP = 00020, wxS_IXGRP = 00010, wxS_IROTH = 00004, wxS_IWOTH = 00002, wxS_IXOTH = 00001, wxPOSIX_USER_READ = wxS_IRUSR, wxPOSIX_USER_WRITE = wxS_IWUSR, wxPOSIX_USER_EXECUTE = wxS_IXUSR, wxPOSIX_GROUP_READ = wxS_IRGRP, wxPOSIX_GROUP_WRITE = wxS_IWGRP, wxPOSIX_GROUP_EXECUTE = wxS_IXGRP, wxPOSIX_OTHERS_READ = wxS_IROTH, wxPOSIX_OTHERS_WRITE = wxS_IWOTH, wxPOSIX_OTHERS_EXECUTE = wxS_IXOTH, wxS_DEFAULT, wxS_DIR_DEFAULT } |
File permission bit names. More... | |
enum | wxSeekMode { wxFromStart, wxFromCurrent, wxFromEnd } |
Parameter indicating how file offset should be interpreted. More... | |
enum | wxFileKind { 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=wxS_DIR_DEFAULT) |
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.
This type is usually just a synonym for off_t
but can be defined as wxLongLong_t
if wxHAS_HUGE_FILES
is defined but off_t
is only 32 bits.
enum wxFileKind |
File kind enumerations returned from wxGetFileKind().
Also used by wxFFile::GetKind() and wxFile::GetKind().
Include file:
#include <wx/filefn.h>
enum wxPosixPermissions |
File permission bit names.
We define these constants in wxWidgets because S_IREAD &c are not standard. However, we do assume that the values correspond to the Unix umask bits.
wxS_IRUSR |
Standard POSIX names for these permission flags with "wx" prefix. |
wxS_IWUSR |
Standard POSIX names for these permission flags with "wx" prefix. |
wxS_IXUSR |
Standard POSIX names for these permission flags with "wx" prefix. |
wxS_IRGRP |
Standard POSIX names for these permission flags with "wx" prefix. |
wxS_IWGRP |
Standard POSIX names for these permission flags with "wx" prefix. |
wxS_IXGRP |
Standard POSIX names for these permission flags with "wx" prefix. |
wxS_IROTH |
Standard POSIX names for these permission flags with "wx" prefix. |
wxS_IWOTH |
Standard POSIX names for these permission flags with "wx" prefix. |
wxS_IXOTH |
Standard POSIX names for these permission flags with "wx" prefix. |
wxPOSIX_USER_READ |
Longer but more readable synonyms for the constants above. |
wxPOSIX_USER_WRITE |
Longer but more readable synonyms for the constants above. |
wxPOSIX_USER_EXECUTE |
Longer but more readable synonyms for the constants above. |
wxPOSIX_GROUP_READ |
Longer but more readable synonyms for the constants above. |
wxPOSIX_GROUP_WRITE |
Longer but more readable synonyms for the constants above. |
wxPOSIX_GROUP_EXECUTE |
Longer but more readable synonyms for the constants above. |
wxPOSIX_OTHERS_READ |
Longer but more readable synonyms for the constants above. |
wxPOSIX_OTHERS_WRITE |
Longer but more readable synonyms for the constants above. |
wxPOSIX_OTHERS_EXECUTE |
Longer but more readable synonyms for the constants above. |
wxS_DEFAULT |
Default mode for the new files: allow reading/writing them to everybody but the effective file mode will be set after ANDing this value with umask and so won't include wxS_IW{GRP,OTH} for the default 022 umask value. |
wxS_DIR_DEFAULT |
Default mode for the new directories (see wxFileName::Mkdir): allow reading/writing/executing them to everybody, but just like wxS_DEFAULT the effective directory mode will be set after ANDing this value with umask. |
enum wxSeekMode |
Parameter indicating how file offset should be interpreted.
This is used by wxFFile::Seek() and wxFile::Seek().
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 | ) |
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 | ) |
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>
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>
char* wxFileNameFromPath | ( | char * | path | ) |
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.
以下に例を示します:
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 | ( | int | fd | ) |
Returns the type of an open file.
Possible return values are enumerations of wxFileKind.
Include file:
#include <wx/filefn.h>
wxFileKind wxGetFileKind | ( | FILE * | fp | ) |
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 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 = wxS_DIR_DEFAULT |
||
) |
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>
bool wxRemoveFile | ( | const wxString & | file | ) |
Renames file1 to file2, returning true if successful.
If file2 is a directory, file1 is moved into it (overwrite is ignored in this case). Otherwise, if file2 is an existing file, it is overwritten if overwrite is true (default) and the function fails if overwrite is false.
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.