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.
See also
Class Hierarchy¶
Methods Summary¶
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. |
Properties Summary¶
See |
Class API¶
- class wx.FileSystem(Object)¶
Possible constructors:
FileSystem() -> None
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
orFindFirst
functions will use current working directory as current path (see also GetCwd).- Return type:
None
- static 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)
- Parameters:
handler (wx.FileSystemHandler)
- Return type:
None
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' !!
- Parameters:
location (string) – the new location. Its meaning depends on the value of is_dir
is_dir (bool) – if
True
location is new directory. IfFalse
(the default) location is file in the new directory.
- Return type:
None
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:
str
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 returnsFalse
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:
str
- FindNext(self)¶
Returns the next filename that matches the parameters passed to
FindFirst
.- Return type:
str
- GetPath(self)¶
Returns the actual path (set by
wx.FileSystem.ChangePathTo
).- Return type:
str
- 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:
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:
- static URLToFileName(url)¶
Converts URL into a well-formed filename.
The URL must use the
file
protocol.- Parameters:
url (string)
- Return type:
str
Properties¶