## File functions

Include files

<wx/utils.h>

See also

wxPathList
wxDir
wxFile
wxFileName

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

### ::wxDirExists

bool wxDirExists(const wxString& dirname)

Returns TRUE if the directory exists.

### ::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. It also returns TRUE if the file is a directory.

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

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.IsEmpty() )
      {
        ...
        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 occured (for example, the directory doesn't exist).

Portability

This function is implemented for Win16 (only for drives less than 2Gb), Win32, Mac OS and generic Unix provided the system has `statfs()` function.

This function first appeared in wxWindows 2.3.2.

### ::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.

### ::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.

### ::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.

### ::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>