Phoenix Logo

phoenix_title wx.FileSystem

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 wx.FileSystemHandler) to provide access to user-defined virtual file systems.


class_hierarchy Class Hierarchy

Inheritance diagram for class FileSystem:

method_summary Methods Summary

__init__ Constructor.
AddHandler This static function adds new handler into the list of handlers (see wx.FileSystemHandler) which provide access to virtual FS.
ChangePathTo Sets the current location.
FileNameToURL Converts a FileName into an URL.
FindFileInPath 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.
FindFirst Works like FindFirstFile .
FindNext Returns the next filename that matches the parameters passed to FindFirst .
GetPath Returns the actual path (set by wx.FileSystem.ChangePathTo ).
HasHandlerForPath This static function returns True if there is a registered handler which can open the given location.
OpenFile Opens the file and returns a pointer to a wx.FSFile object or None if failed.
RemoveHandler Remove a filesystem handler from the list of handlers.
URLToFileName Converts URL into a well-formed filename.

property_summary Properties Summary

Path See GetPath

api Class API



class wx.FileSystem(Object)

Possible constructors:

FileSystem()

This class provides an interface for opening files on different file systems.


Methods



__init__(self)

Constructor.

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



static AddHandler(handler)

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

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

Parameters:handler (wx.FileSystemHandler) –

Note

You can call:

wx.FileSystem.AddHandler(My_FS_Handler)

This is because (a) AddHandler is a static method, and (b) the handlers are deleted in wx.FileSystem‘s destructor so that you don’t have to care about it.



ChangePathTo(self, location, is_dir=False)

Sets the current location.

location parameter passed to OpenFile is relative to this path.

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 (string) – the new location. Its meaning depends on the value of is_dir
  • is_dir (bool) – if True location is new directory. If False (the default) location is file in the new directory.

Note

Unless is_dir is True the location parameter is not the directory name but the name of the file in this directory.



static FileNameToURL(filename)

Converts a FileName into an URL.

Parameters:filename (string) –
Return type:string

See also

URLToFileName , FileName



FindFileInPath(self, pStr, path, 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 (string) – Receives the full path of the file, must not be None
  • path (string) – PATH_SEP-separated list of directories
  • file (string) – the name of the file to look for
Return type:

bool



FindFirst(self, wildcard, flags=0)

Works like FindFirstFile .

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

Parameters:
  • wildcard (string) – The wildcard that the filename must match
  • flags (int) – One of FILE (only files), DIR (only directories) or 0 (both).
Return type:

string



FindNext(self)

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

Return type:string


GetPath(self)

Returns the actual path (set by wx.FileSystem.ChangePathTo ).

Return type:string


static HasHandlerForPath(location)

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

Parameters:location (string) –
Return type:bool


OpenFile(self, location, flags=FS_READ)

Opens the file and returns a pointer to a wx.FSFile object or None 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 wx.FSFile. flags can be one or more of the wx.FileSystemOpenFlags values combined together.

A stream opened with just the default wx.FS_READ flag may or may not be seekable depending on the underlying source.

Passing “wx``wx.FS_READ`` | wx.FS_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.

Parameters:
  • location (string) –
  • flags (int) –
Return type:

wx.FSFile

Note

The location argument is, despite this method’s name not a filename. It is a “location”, aka wx.FileSystem URL (see FileSystem Overview).



static RemoveHandler(handler)

Remove a filesystem handler from the list of handlers.

Parameters:handler (wx.FileSystemHandler) –
Return type: wx.FileSystemHandler


static URLToFileName(url)

Converts URL into a well-formed filename.

The URL must use the file protocol.

Parameters:url (string) –
Return type:string

Properties



Path

See GetPath