## File functions

Include files

<wx/utils.h>

See also

wxPathList, wxDir, wxFile

::wxDirExists
::wxDos2UnixFilename
::wxFileExists
::wxFileModificationTime
::wxFileNameFromPath
::wxFindFirstFile
::wxFindNextFile
::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 Dos2UnixFilename(const wxString& 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)

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.

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

Copies file1 to file2, returning TRUE if successful.

### ::wxGetCwd

wxString wxGetCwd()

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

### ::wxGetWorkingDirectory

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

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)

Makes a temporary filename based on prefix, opens and closes the file, and places the name in buf. If buf is NULL, new store is allocated for the temporary filename using new.

Under Windows, the filename will include the drive and name of the directory allocated for temporary files (usually the contents of the TEMP variable). Under Unix, the `/tmp` directory is used.

It is the application's responsibility to create and delete the file.

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

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

Use of this function requires the file wx_doc.h to be included.

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

Use of this function requires the file wx_doc.h to be included.