Contents Up Previous Next

File functions

Include files

<wx/utils.h>

See also

wxPathList

::wxDirExists
::wxDos2UnixFilename
::wxFileExists
::wxFileNameFromPath
::wxFindFirstFile
::wxFindNextFile
::wxGetOSDirectory
::wxIsAbsolutePath
::wxPathOnly
::wxUnix2DosFilename
::wxConcatFiles
::wxCopyFile
::wxGetCwd
::wxGetHostName
::wxGetEmailAddress
::wxGetUserId
::wxGetUserName
::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.


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

spec may contain wildcards.

flags is reserved for future use.

For example:

  wxString f = wxFindFirstFile("/home/project/*.*");
  while ( !f.IsEmpty() )
  {
    ...
    f = wxFindNextFile();
  }

::wxFindNextFile

wxString wxFindFirstFile()

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


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


::wxGetHostName

bool wxGetHostName(const wxString& buf, int sz)

Copies the current host machine's name into the supplied buffer.

Under Windows or NT, this function first looks in the environment variable SYSTEM_NAME; if this is not found, the entry HostName in the wxWindows section of the WIN.INI file is tried.

Returns TRUE if successful, FALSE otherwise.


::wxGetEmailAddress

bool wxGetEmailAddress(const wxString& buf, int sz)

Copies the user's email address into the supplied buffer, by concatenating the values returned by wxGetHostName and wxGetUserId.

Returns TRUE if successful, FALSE otherwise.


::wxGetUserId

bool wxGetUserId(const wxString& buf, int sz)

Copies the current user id into the supplied buffer.

Under Windows or NT, this function first looks in the environment variables USER and LOGNAME; if neither of these is found, the entry UserId in the wxWindows section of the WIN.INI file is tried.

Returns TRUE if successful, FALSE otherwise.


::wxGetUserName

bool wxGetUserName(const wxString& buf, int sz)

Copies the current user name into the supplied buffer.

Under Windows or NT, this function looks for the entry UserName in the wxWindows section of the WIN.INI file. If PenWindows is running, the entry Current in the section User of the PENWIN.INI file is used.

Returns TRUE if successful, FALSE otherwise.


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

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)

Makes the directory dir, returning TRUE if successful.


::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, const wxString * path, const wxString * name, const 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.