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.
See also
wx.FileSystemHandler, wx.FSFile, FileSystem Overview
Constructor. |
|
This static function adds a new handler into the list of handlers which provide access to virtual |
|
Sets the current location. |
|
Converts a FileName into an URL. |
|
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. |
|
Works like |
|
Returns the next filename that matches the parameters passed to |
|
Returns the actual path (set by |
|
This static function returns |
|
Opens the file and returns a pointer to a wx.FSFile object or |
|
Remove a filesystem handler from the list of handlers. |
|
Converts URL into a well-formed filename. |
See |
wx.
FileSystem
(Object)¶Possible constructors:
FileSystem()
This class provides an interface for opening files on different file systems.
__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).
AddHandler
(handler)¶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:
wx.FileSystem.AddHandler(My_FS_Handler)
handler (wx.FileSystemHandler) –
Note
If two handlers for the same protocol are added, the last added one takes precedence.
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' !!
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.
FileNameToURL
(filename)¶Converts a FileName into an URL.
filename (string) –
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.
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
bool
FindFirst
(self, wildcard, flags=0)¶Works like FindFirstFile
.
Returns the name of the first filename (within filesystem’s current path) that matches wildcard.
wildcard (string) – The wildcard that the filename must match
flags (int) – One of FILE
(only files), DIR
(only directories) or 0 (both).
string
FindNext
(self)¶Returns the next filename that matches the parameters passed to FindFirst
.
string
GetPath
(self)¶Returns the actual path (set by wx.FileSystem.ChangePathTo
).
string
HasHandlerForPath
(location)¶This static function returns True
if there is a registered handler which can open the given location.
location (string) –
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.
location (string) –
flags (int) –
Note
The location argument is, despite this method’s name not a filename. It is a “location”, aka wx.FileSystem URL (see FileSystem Overview).
RemoveHandler
(handler)¶Remove a filesystem handler from the list of handlers.
handler (wx.FileSystemHandler) –
URLToFileName
(url)¶Converts URL into a well-formed filename.
The URL must use the file
protocol.
url (string) –
string