Collection of useful WrapFS subclasses.

Here’s an example that opens a filesystem then makes it read only:

>>> from fs import open_fs
>>> from fs.wrap import read_only
>>> projects_fs = open_fs('~/projects')
>>> read_only_projects_fs = read_only(projects_fs)
>>> read_only_projects_fs.remove('__init__.py')
Traceback (most recent call last):
fs.errors.ResourceReadOnly: resource '__init__.py' is read only
class fs.wrap.WrapCachedDir(wrap_fs)[source]

Caches filesystem directory information.

This filesystem caches directory information retrieved from a scandir call. This may speed up code that calls isdir, isfile, or gettype too frequently.


Using this wrap will prevent changes to directory information being visible to the filesystem object. Consequently it is best used only in a fairly limited scope where you don’t expected anything on the filesystem to change.

class fs.wrap.WrapReadOnly(wrap_fs)[source]

Makes a Filesystem read-only.

Any call that would would write data or modify the filesystem in any way will raise a ResourceReadOnly exception.


Make a filesystem that caches directory information.

Parameters:fs (FS) – A filesystem instance.
Returns:A filesystem that caches results of scandir, isdir and other methods which read directory information.
Return type:FS

Make a read-only filesystem.

Parameters:fs (FS) – A filesystem instance.
Returns:A read only version of fs
Return type:FS