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
__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. |
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 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: |
|
---|
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.
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: |
|
---|---|
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: |
|
---|---|
Return type: |
|
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 |
---|
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: |
|
---|---|
Return type: |
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.
Parameters: | handler (wx.FileSystemHandler) – |
---|---|
Return type: | wx.FileSystemHandler |
URLToFileName
(url)¶Converts URL into a well-formed filename.
The URL must use the file
protocol.
Parameters: | url (string) – |
---|---|
Return type: | string |