fs.osfs

Exposes the OS Filesystem as an FS object.

For example, to print all the files and directories in the OS root:

>>> from fs.osfs import OSFS
>>> home_fs = OSFS('/')
>>> print home_fs.listdir()
class fs.osfs.OSFS(root_path, thread_synchronize=True, encoding=None, create=False, dir_mode=448, use_long_paths=True)

Expose the underlying operating-system filesystem as an FS object.

This is the most basic of filesystems, which simply shadows the underlaying filesystem of the OS. Most of its methods simply defer to the matching methods in the os and os.path modules.

Creates an FS object that represents the OS Filesystem under a given root path

Parameters:
  • root_path – The root OS path
  • thread_synchronize – If True, this object will be thread-safe by use of a threading.Lock object
  • encoding – The encoding method for path strings
  • create – If True, then root_path will be created if it doesn’t already exist
  • dir_mode – The mode to use when creating the directory
unsyspath(path)

Convert a system-level path into an FS-level path.

This basically the reverse of getsyspath(). If the path does not refer to a location within this filesystem, ValueError is raised.

Parameters:path – a system path
Returns:a path within this FS object
Return type:string