Public Member Functions | Static Public Member Functions

# wxFileSystem Class Reference
[Virtual File System]

`#include <wx/filesys.h>`

Inheritance diagram for wxFileSystem:
[legend]

## Detailed Description

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 (see wxFileSystemHandler) to provide access to user-defined virtual file systems.

##

Library: wxBase
Category: Virtual File System

See also:
  wxFileSystemHandler, wxFSFile, wxFileSystem Overview

## Public Member Functions
| wxFileSystem ()
| Constructor.
void | ChangePathTo (const wxString &location, bool is_dir=false)
| Sets the current location.
bool | FindFileInPath (wxString *pStr, const wxString &path, const wxString &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.
wxString | FindFirst (const wxString &wildcard, int flags=0)
| Works like wxFindFirstFile().
wxString | FindNext ()
| Returns the next filename that matches the parameters passed to FindFirst().
wxString | GetPath () const
| Returns the actual path (set by wxFileSystem::ChangePathTo).
wxFSFile * | OpenFile (const wxString &location, int flags=wxFS_READ)
| Opens the file and returns a pointer to a wxFSFile object or NULL if failed.
## Static Public Member Functions
static void | AddHandler (wxFileSystemHandler *handler)
| This static function adds new handler into the list of handlers (see wxFileSystemHandler) which provide access to virtual FS.
static wxString | FileNameToURL (const wxFileName &filename)
| Converts a wxFileName into an URL.
static bool | HasHandlerForPath (const wxString &location)
| This static function returns true if there is a registered handler which can open the given location.
static wxFileName | URLToFileName (const wxString &url)
| Converts URL into a well-formed filename.

List of all members.

## Constructor & Destructor Documentation

wxFileSystem::wxFileSystem | ( |  | ) |

Constructor.

The initial current path of this object will be empty (i.e. GetPath() == wxEmptyString) which means that e.g. OpenFile() or FindFirst() functions will use current working directory as current path (see also wxGetCwd).

## Member Function Documentation

static void wxFileSystem::AddHandler | ( | wxFileSystemHandler * | handler | ) | `[static]`

This static function adds new handler into the list of handlers (see wxFileSystemHandler) which provide access to virtual FS.

Note that if two handlers for the same protocol are added, the last added one 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.

void wxFileSystem::ChangePathTo | ( | const wxString & | location,
|  | bool | is_dir = `false` |
| ) |  |  |

Sets the current location.

location parameter passed to OpenFile() is relative to this path.

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

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' !!

Parameters:

  | location | the new location. Its meaning depends on the value of is_dir
  | is_dir | if true location is new directory. If false (the default) location is file in the new directory.

static wxString wxFileSystem::FileNameToURL | ( | const wxFileName & | filename | ) | `[static]`

Converts a wxFileName into an URL.

See also:
  URLToFileName(), wxFileName

bool wxFileSystem::FindFileInPath | ( | wxString * | pStr,
|  | const wxString & | path,
|  | const wxString & | 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:

  | pStr | Receives the full path of the file, must not be NULL
  | path | wxPATH_SEP-separated list of directories
  | file | the name of the file to look for

wxString wxFileSystem::FindFirst | ( | const wxString & | wildcard,
|  | int | flags = `0` |
| ) |  |  |

Works like wxFindFirstFile().

Returns the name of the first filename (within filesystem's current path) that matches wildcard.

Parameters:

  | wildcard | The wildcard that the filename must match
  | flags | One of wxFILE (only files), wxDIR (only directories) or 0 (both).

wxString wxFileSystem::FindNext | ( |  | ) |

Returns the next filename that matches the parameters passed to FindFirst().

wxString wxFileSystem::GetPath | ( |  | ) | const

Returns the actual path (set by wxFileSystem::ChangePathTo).

static bool wxFileSystem::HasHandlerForPath | ( | const wxString & | location | ) | `[static]`

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

wxFSFile* wxFileSystem::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 wxFileSystemOpenFlags values combined together.

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.

Note:
  The location argument is, despite this method's name not a filename. It is a "location", aka wxFileSystem URL (see wxFileSystem Overview).

static wxFileName wxFileSystem::URLToFileName | ( | const wxString & | url | ) | `[static]`

Converts URL into a well-formed filename.

The URL must use the `file` protocol.

|  | [ top ]