Contents Up Previous Next

wxFileSystem

This class provides an interface for opening files on different file systems. It can handle absolute and/or local filenames. It uses a system of handlers to provide access to user-defined virtual file systems.

Derived from

wxObject

Include files

<wx/filesys.h>

See Also

wxFileSystemHandler, wxFSFile, Overview

Members

wxFileSystem::wxFileSystem
wxFileSystem::AddHandler
wxFileSystem::HasHandlerForPath
wxFileSystem::ChangePathTo
wxFileSystem::GetPath
wxFileSystem::FileNameToURL
wxFileSystem::FindFileInPath
wxFileSystem::FindFirst
wxFileSystem::FindNext
wxFileSystem::OpenFile
wxFileSystem::URLToFileName


wxFileSystem::wxFileSystem

wxFileSystem()

Constructor.


wxFileSystem::AddHandler

static void AddHandler(wxFileSystemHandler *handler)

This static function adds new handler into the list of handlers which provide access to virtual FS. Note that if two handlers for the same protocol are added, the last one added takes precedence.

Note

You can call:

wxFileSystem::AddHandler(new My_FS_Handler);
This is because (a) AddHandler is a static method, and (b) the handlers are deleted in wxFileSystem's destructor so that you don't have to care about it.


wxFileSystem::HasHandlerForPath

static bool HasHandlerForPath(const wxString & location)

This static function returns true if there is a registered handler which can open the given location.


wxFileSystem::ChangePathTo

void ChangePathTo(const wxString& location, bool is_dir = false)

Sets the current location. location parameter passed to OpenFile is relative to this path.

Caution! Unless is_dir is true the location parameter is not the directory name but the name of the file in this directory. All these commands change the path to "dir/subdir/":

  ChangePathTo("dir/subdir/xh.htm");
  ChangePathTo("dir/subdir", true);
  ChangePathTo("dir/subdir/", true);
Parameters

location

is_dir

Example

  f = fs -> OpenFile("hello.htm"); // opens file 'hello.htm'
  fs -> ChangePathTo("subdir/folder", true);
  f = fs -> OpenFile("hello.htm"); // opens file 'subdir/folder/hello.htm' !!

wxFileSystem::GetPath

wxString GetPath()

Returns actual path (set by ChangePathTo).


wxFileSystem::FileNameToURL

static wxString FileNameToURL(wxFileName filename)

Converts filename into URL.

See also

wxFileSystem::URLToFileName, wxFileName


wxFileSystem::FindFileInPath

bool FindFileInPath(wxString *str, const wxChar *path, const wxChar *file)

Looks for the file with the given name file in a colon or semi-colon (depending on the current platform) separated list of directories in path. If the file is found in any directory, returns true and the full path of the file in str, otherwise returns false and doesn't modify str.

Parameters

str

path

file


wxFileSystem::FindFirst

wxString FindFirst(const wxString& wildcard, int flags = 0)

Works like wxFindFirstFile. Returns name of the first filename (within filesystem's current path) that matches wildcard. flags may be one of wxFILE (only files), wxDIR (only directories) or 0 (both).


wxFileSystem::FindNext

wxString FindNext()

Returns the next filename that matches parameters passed to FindFirst.


wxFileSystem::OpenFile

wxFSFile* OpenFile(const wxString& location, int flags = wxFS_READ)

Opens the file and returns a pointer to a wxFSFile object or NULL if failed. It first tries to open the file in relative scope (based on value passed to ChangePathTo() method) and then as an absolute path. Note that the user is responsible for deleting the returned wxFSFile.

flags can be one or more of the following bit values ored together:

// Open Bit Flags
enum {
    wxFS_READ = 1,      // Open for reading
    wxFS_SEEKABLE = 4   // Returned stream will be seekable
};
A stream opened with just the default wxFS_READ flag may or may not be seekable depending on the underlying source. Passing wxFS_READ | wxFS_SEEKABLE for flags will back a stream that is not natively seekable with memory or a file and return a stream that is always seekable.


wxFileSystem::URLToFileName

static wxFileName URLToFileName(const wxString& url)

Converts URL into a well-formed filename. The URL must use the file protocol.

See also

wxFileSystem::FileNameToURL, wxFileName