Sub Filesystem¶
Manage a directory in a parent filesystem.
-
class
fs.subfs.
SubFS
(parent_fs, path)[source]¶ A sub-directory on a parent filesystem.
A SubFS is a filesystem object that maps to a sub-directory of another filesystem. This is the object that is returned by
opendir
.-
__init__
(parent_fs, path)[source]¶ Create a filesystem. See help(type(self)) for accurate signature.
-
-
class
fs.subfs.
ClosingSubFS
(parent_fs, path)[source]¶ A version of
SubFS
which closes its parent when closed.-
close
()[source]¶ Close the filesystem and release any resources.
It is important to call this method when you have finished working with the filesystem. Some filesystems may not finalize changes until they are closed (archives for example). You may call this method explicitly (it is safe to call close multiple times), or you can use the filesystem as a context manager to automatically close.
Example
>>> with OSFS('~/Desktop') as desktop_fs: ... desktop_fs.writetext( ... 'note.txt', ... "Don't forget to tape Game of Thrones" ... )
If you attempt to use a filesystem that has been closed, a
FilesystemClosed
exception will be thrown.
-