| Version: 3.2.5

Public Member Functions | Static Public Member Functions | List of all members
wxFileSystem Class Reference
Class List by Category » 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. More...
void | ChangePathTo (const wxString &location, bool is_dir=false)
| Sets the current location. More...
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. More...
wxString | FindFirst (const wxString &wildcard, int flags=0)
| Works like wxFindFirstFile(). More...
wxString | FindNext ()
| Returns the next filename that matches the parameters passed to FindFirst(). More...
wxString | GetPath () const
| Returns the actual path (set by wxFileSystem::ChangePathTo). More...
wxFSFile * | OpenFile (const wxString &location, int flags=wxFS_READ)
| Opens the file and returns a pointer to a wxFSFile object or NULL if failed. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Static Public Member Functions

static void | AddHandler (wxFileSystemHandler *handler)
| This static function adds a new handler into the list of handlers which provide access to virtual FS. More...
static wxFileSystemHandler * | RemoveHandler (wxFileSystemHandler *handler)
| Remove a filesystem handler from the list of handlers. More...
static wxString | FileNameToURL (const wxFileName &filename)
| Converts a wxFileName into an URL. More...
static bool | HasHandlerForPath (const wxString &location)
| This static function returns true if there is a registered handler which can open the given location. More...
static wxFileName | URLToFileName (const wxString &url)
| Converts URL into a well-formed filename. More...

## Additional Inherited Members

Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ wxFileSystem()

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

## ◆ AddHandler()

static void wxFileSystem::AddHandler | ( | wxFileSystemHandler * | handler | ) |

static

This static function adds a new handler into the list of handlers which provide access to virtual FS.

handler must be a heap-allocated object which will be deleted if it is removed by RemoveHandler() or at program shutdown.

Typical example of use:

wxFileSystem::AddHandler(new wxZipFSHandler);
wxArchiveFSHandler
A file system handler for accessing files inside of archives.
Definition: fs_arc.h:15
wxFileSystem::AddHandler
static void AddHandler(wxFileSystemHandler *handler)
This static function adds a new handler into the list of handlers which provide access to virtual FS.

Note
  If two handlers for the same protocol are added, the last added one takes precedence.

## ◆ ChangePathTo()

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);
wxFileSystem::ChangePathTo
void ChangePathTo(const wxString &location, bool is_dir=false)
Sets the current location.

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.

## ◆ FileNameToURL()

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

static

Converts a wxFileName into an URL.

See also
  URLToFileName(), wxFileName

## ◆ FindFileInPath()

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

## ◆ FindFirst()

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

## ◆ FindNext()

wxString wxFileSystem::FindNext | ( |  | ) |

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

## ◆ GetPath()

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

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

## ◆ HasHandlerForPath()

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.

## ◆ OpenFile()

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

## ◆ RemoveHandler()

static wxFileSystemHandler* wxFileSystem::RemoveHandler | ( | wxFileSystemHandler * | handler | ) |

static

Remove a filesystem handler from the list of handlers.

## ◆ URLToFileName()

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

static

Converts URL into a well-formed filename.

The URL must use the `file` protocol.