An OSFS (OS FileSystem) manages the files and directories supplied by your operating system.
Here's how you can open a OSFS object for the current working directory:
from fs import open_fs
cwd_fs = open_fs('./')
Or if you prefer explicit construction of the OSFS class:
from fs.osfs import OSFS
cwd_fs = OSFS('./')
Like all Filesystem classes the OSFS has a simple interface designed to be comfortably familiar to Python devs. In the case of OSFS, it is a fairly thin wrapper around the os
and io
modules in the standard library.
Here's how you would open a file:
with cwd_fs.open('foo.txt', 'wt') as foo_file:
foo_file.write('Hello, World!')
Or you could use the following shortcut:
cwd_fs.settext('foo.txt', 'Hello, World!')
See the OSFS docs for more information.