## File functions

Include files

<wx/filefn.h>

See also

wxPathList
wxDir
wxFile
wxFileName

::wxDos2UnixFilename
::wxFileExists
::wxFileModificationTime
::wxFileNameFromPath
::wxFindFirstFile
::wxFindNextFile
::wxGetDiskSpace
::wxGetFileKind
::wxGetOSDirectory
::wxIsAbsolutePath
::wxDirExists
::wxPathOnly
::wxUnix2DosFilename
wxCHANGE_UMASK
::wxConcatFiles
::wxCopyFile
::wxGetCwd
::wxGetWorkingDirectory
::wxGetTempFileName
::wxIsWild
::wxMatchWild
::wxMkdir
::wxParseCommonDialogsFilter
::wxRemoveFile
::wxRenameFile
::wxRmdir
::wxSetWorkingDirectory
::wxSplitPath
::wxTransferFileToStream
::wxTransferStreamToFile

### ::wxDos2UnixFilename

void wxDos2UnixFilename(wxChar *s)

Converts a DOS to a Unix filename by replacing backslashes with forward slashes.

### ::wxFileExists

bool wxFileExists(const wxString& filename)

Returns true if the file exists and is a plain file.

### ::wxFileModificationTime

time_t wxFileModificationTime(const wxString& filename)

Returns time of last modification of given file.

### ::wxFileNameFromPath

wxString wxFileNameFromPath(const wxString& path)

char * wxFileNameFromPath(char *path)

NB: This function is obsolete, please use wxFileName::SplitPath instead.

Returns the filename for a full path. The second form returns a pointer to temporary storage that should not be deallocated.

### ::wxFindFirstFile

wxString wxFindFirstFile(const char *spec, int flags = 0)

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 "..".

Warning

As of wx 2.5.2, these functions are not thread-safe! (they use static variables). You probably want to use wxDir::GetFirst or wxDirTraverser instead.

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();
      }

### ::wxFindNextFile

wxString wxFindNextFile()

Returns the next file that matches the path passed to wxFindFirstFile.

See wxFindFirstFile for an example.

### ::wxGetDiskSpace

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.

Returns

`true` on success, `false` if an error occurred (for example, the directory doesn't exist).

Portability

This function is implemented for Win32, Mac OS and generic Unix provided the system has `statfs()` function.

This function first appeared in wxWidgets 2.3.2.

### ::wxGetFileKind

wxFileKind wxGetFileKind(int fd)

wxFileKind wxGetFileKind(FILE *fp)

Returns the type of an open file. Possible return values are:

    enum wxFileKind
    {
      wxFILE_KIND_UNKNOWN,
      wxFILE_KIND_DISK,     // a file supporting seeking to arbitrary offsets
      wxFILE_KIND_TERMINAL, // a tty
      wxFILE_KIND_PIPE      // a pipe
    };

Include files

<wx/filefn.h>

### ::wxGetOSDirectory

wxString wxGetOSDirectory()

Returns the Windows directory under Windows; on other platforms returns the empty string.

### ::wxIsAbsolutePath

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.

### ::wxDirExists

bool wxDirExists(const wxString& dirname)

Returns true if the path exists.

### ::wxPathOnly

wxString wxPathOnly(const wxString& path)

Returns the directory part of the filename.

### ::wxUnix2DosFilename

void wxUnix2DosFilename(const wxString& s)

Converts a Unix to a DOS filename by replacing forward slashes with backslashes.

### wxCHANGE_UMASK

wxCHANGE_UMASK(int 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.

### ::wxConcatFiles

bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3)

Concatenates file1 and file2 to file3, returning true if successful.

### ::wxCopyFile

bool wxCopyFile(const wxString& file1, const wxString& file2, bool overwrite = true)

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.

### ::wxGetCwd

wxString wxGetCwd()

Returns a string containing the current (or working) directory.

### ::wxGetWorkingDirectory

wxString wxGetWorkingDirectory(char *buf=NULL, int sz=1000)

NB: This function is obsolete: use wxGetCwd instead.

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.

### ::wxGetTempFileName

char * wxGetTempFileName(const wxString& prefix, char *buf=NULL)

bool wxGetTempFileName(const wxString& prefix, wxString& buf)

NB: These functions are obsolete, please use wxFileName::CreateTempFileName instead.

### ::wxIsWild

bool wxIsWild(const wxString& pattern)

Returns true if the pattern contains wildcards. See wxMatchWild.

### ::wxMatchWild

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. See wxIsWild.

### ::wxMkdir

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 effect for the other ones.

### ::wxParseCommonDialogsFilter

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"

### ::wxRemoveFile

bool wxRemoveFile(const wxString& file)

Removes file, returning true if successful.

### ::wxRenameFile

bool wxRenameFile(const wxString& file1, const wxString& file2)

Renames file1 to file2, returning true if successful.

### ::wxRmdir

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.

### ::wxSetWorkingDirectory

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.

### ::wxSplitPath

void wxSplitPath(const char * fullname, wxString * path, wxString * name, wxString * ext)

NB: This function is obsolete, please use wxFileName::SplitPath instead.

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).

### ::wxTransferFileToStream

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 files

<wx/docview.h>

### ::wxTransferStreamToFile

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 files

<wx/docview.h>