操作系统文件系统¶
管理操作系统提供的文件系统。
本质上, OSFS
是Python库中的 io
和 os
模块的一个兼容层。
-
class
fs.osfs.
OSFS
(root_path, create=False, create_mode=511, encoding=None)¶ Create an OSFS.
参数: - root_path (str) – An OS path to the location on your HD you wish to manage.
- create (bool) – Set to
True
to create the root directory if it does not already exist, otherwise the directory should exist prior to creating theOSFS
instance. - create_mode (int) – The permissions that will be used to create
the directory if
create
is True and the path doesn’t exist, defaults to0o777
. - encoding (str) – The encoding to use for paths, or
None
(default) to auto-detect.
引发: fs.errors.CreateFailed – If
root_path
does not exists, or could not be created.Here are some examples of creating
OSFS
objects:current_directory_fs = OSFS('.') home_fs = OSFS('~/') windows_system32_fs = OSFS('c://system32')