文件和目录访问¶
本章中描述的模块处理磁盘文件和目录。 例如,有一些模块用于读取文件的属性,以可移植的方式操作路径以及创建临时文件。 本章的完整模块列表如下:
- pathlib--- 面向对象的文件系统路径- 基础使用
- Exceptions
- 纯路径- PurePath
- PurePosixPath
- PureWindowsPath
- 通用性质
- 运算符
- 访问个别部分
- 方法和特征属性- PurePath.pathmod
- PurePath.drive
- PurePath.root
- PurePath.anchor
- PurePath.parents
- PurePath.parent
- PurePath.name
- PurePath.suffix
- PurePath.suffixes
- PurePath.stem
- PurePath.as_posix()
- PurePath.as_uri()
- PurePath.is_absolute()
- PurePath.is_relative_to()
- PurePath.is_reserved()
- PurePath.joinpath()
- PurePath.match()
- PurePath.relative_to()
- PurePath.with_name()
- PurePath.with_stem()
- PurePath.with_suffix()
- PurePath.with_segments()
 
 
- 具体路径- Path
- PosixPath
- WindowsPath
- 方法- Path.cwd()
- Path.home()
- Path.from_uri()
- Path.stat()
- Path.chmod()
- Path.exists()
- Path.expanduser()
- Path.glob()
- Path.group()
- Path.is_dir()
- Path.is_file()
- Path.is_junction()
- Path.is_mount()
- Path.is_symlink()
- Path.is_socket()
- Path.is_fifo()
- Path.is_block_device()
- Path.is_char_device()
- Path.iterdir()
- Path.walk()
- Path.lchmod()
- Path.lstat()
- Path.mkdir()
- Path.open()
- Path.owner()
- Path.read_bytes()
- Path.read_text()
- Path.readlink()
- Path.rename()
- Path.replace()
- Path.absolute()
- Path.resolve()
- Path.rglob()
- Path.rmdir()
- Path.samefile()
- Path.symlink_to()
- Path.hardlink_to()
- Path.touch()
- Path.unlink()
- Path.write_bytes()
- Path.write_text()
 
 
- 对应的 os模块的工具
 
- os.path--- 常用路径操作- abspath()
- basename()
- commonpath()
- commonprefix()
- dirname()
- exists()
- lexists()
- expanduser()
- expandvars()
- getatime()
- getmtime()
- getctime()
- getsize()
- isabs()
- isfile()
- isdir()
- isjunction()
- islink()
- ismount()
- isdevdrive()
- join()
- normcase()
- normpath()
- realpath()
- relpath()
- samefile()
- sameopenfile()
- samestat()
- split()
- splitdrive()
- splitroot()
- splitext()
- supports_unicode_filenames
 
- fileinput--- 迭代来自多个输入流的行
- stat--- 解析- stat()结果- S_ISDIR()
- S_ISCHR()
- S_ISBLK()
- S_ISREG()
- S_ISFIFO()
- S_ISLNK()
- S_ISSOCK()
- S_ISDOOR()
- S_ISPORT()
- S_ISWHT()
- S_IMODE()
- S_IFMT()
- filemode()
- ST_MODE
- ST_INO
- ST_DEV
- ST_NLINK
- ST_UID
- ST_GID
- ST_SIZE
- ST_ATIME
- ST_MTIME
- ST_CTIME
- S_IFSOCK
- S_IFLNK
- S_IFREG
- S_IFBLK
- S_IFDIR
- S_IFCHR
- S_IFIFO
- S_IFDOOR
- S_IFPORT
- S_IFWHT
- S_ISUID
- S_ISGID
- S_ISVTX
- S_IRWXU
- S_IRUSR
- S_IWUSR
- S_IXUSR
- S_IRWXG
- S_IRGRP
- S_IWGRP
- S_IXGRP
- S_IRWXO
- S_IROTH
- S_IWOTH
- S_IXOTH
- S_ENFMT
- S_IREAD
- S_IWRITE
- S_IEXEC
- UF_NODUMP
- UF_IMMUTABLE
- UF_APPEND
- UF_OPAQUE
- UF_NOUNLINK
- UF_COMPRESSED
- UF_HIDDEN
- SF_ARCHIVED
- SF_IMMUTABLE
- SF_APPEND
- SF_NOUNLINK
- SF_SNAPSHOT
- FILE_ATTRIBUTE_ARCHIVE
- FILE_ATTRIBUTE_COMPRESSED
- FILE_ATTRIBUTE_DEVICE
- FILE_ATTRIBUTE_DIRECTORY
- FILE_ATTRIBUTE_ENCRYPTED
- FILE_ATTRIBUTE_HIDDEN
- FILE_ATTRIBUTE_INTEGRITY_STREAM
- FILE_ATTRIBUTE_NORMAL
- FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
- FILE_ATTRIBUTE_NO_SCRUB_DATA
- FILE_ATTRIBUTE_OFFLINE
- FILE_ATTRIBUTE_READONLY
- FILE_ATTRIBUTE_REPARSE_POINT
- FILE_ATTRIBUTE_SPARSE_FILE
- FILE_ATTRIBUTE_SYSTEM
- FILE_ATTRIBUTE_TEMPORARY
- FILE_ATTRIBUTE_VIRTUAL
- IO_REPARSE_TAG_SYMLINK
- IO_REPARSE_TAG_MOUNT_POINT
- IO_REPARSE_TAG_APPEXECLINK
 
- filecmp--- 文件及目录的比较- cmp()
- cmpfiles()
- clear_cache()
- dircmp类- dircmp- dircmp.report()
- dircmp.report_partial_closure()
- dircmp.report_full_closure()
- dircmp.left
- dircmp.right
- dircmp.left_list
- dircmp.right_list
- dircmp.common
- dircmp.left_only
- dircmp.right_only
- dircmp.common_dirs
- dircmp.common_files
- dircmp.common_funny
- dircmp.same_files
- dircmp.diff_files
- dircmp.funny_files
- dircmp.subdirs
 
- DEFAULT_IGNORES
 
 
- tempfile--- 生成临时文件和目录
- glob--- Unix 风格路径名模式扩展
- fnmatch--- Unix 文件名模式匹配
- linecache--- 随机读写文本行
- shutil--- 高阶文件操作