File and Directory Access¶
The modules described in this chapter deal with disk files and directories. For example, there are modules for reading the properties of files, manipulating paths in a portable way, and creating temporary files. The full list of modules in this chapter is:
pathlib— Object-oriented filesystem paths- Basic use
- Pure paths
- Concrete paths
- Correspondence to tools in the
osmodule
os.path— Common pathname manipulationsabspath()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— Iterate over lines from multiple input streamsstat— Interpretingstat()resultsS_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_MODEST_INOST_DEVST_NLINKST_UIDST_GIDST_SIZEST_ATIMEST_MTIMEST_CTIMES_IFSOCKS_IFLNKS_IFREGS_IFBLKS_IFDIRS_IFCHRS_IFIFOS_IFDOORS_IFPORTS_IFWHTS_ISUIDS_ISGIDS_ISVTXS_IRWXUS_IRUSRS_IWUSRS_IXUSRS_IRWXGS_IRGRPS_IWGRPS_IXGRPS_IRWXOS_IROTHS_IWOTHS_IXOTHS_ENFMTS_IREADS_IWRITES_IEXECUF_NODUMPUF_IMMUTABLEUF_APPENDUF_OPAQUEUF_NOUNLINKUF_COMPRESSEDUF_HIDDENSF_ARCHIVEDSF_IMMUTABLESF_APPENDSF_NOUNLINKSF_SNAPSHOTFILE_ATTRIBUTE_ARCHIVEFILE_ATTRIBUTE_COMPRESSEDFILE_ATTRIBUTE_DEVICEFILE_ATTRIBUTE_DIRECTORYFILE_ATTRIBUTE_ENCRYPTEDFILE_ATTRIBUTE_HIDDENFILE_ATTRIBUTE_INTEGRITY_STREAMFILE_ATTRIBUTE_NORMALFILE_ATTRIBUTE_NOT_CONTENT_INDEXEDFILE_ATTRIBUTE_NO_SCRUB_DATAFILE_ATTRIBUTE_OFFLINEFILE_ATTRIBUTE_READONLYFILE_ATTRIBUTE_REPARSE_POINTFILE_ATTRIBUTE_SPARSE_FILEFILE_ATTRIBUTE_SYSTEMFILE_ATTRIBUTE_TEMPORARYFILE_ATTRIBUTE_VIRTUALIO_REPARSE_TAG_SYMLINKIO_REPARSE_TAG_MOUNT_POINTIO_REPARSE_TAG_APPEXECLINK
filecmp— File and Directory Comparisonstempfile— Generate temporary files and directoriesglob— Unix style pathname pattern expansionfnmatch— Unix filename pattern matchinglinecache— Random access to text linesshutil— High-level file operations
See also
- Module
os Operating system interfaces, including functions to work with files at a lower level than Python file objects.
- Module
io Python’s built-in I/O library, including both abstract classes and some concrete classes such as file I/O.
- Built-in function
open() The standard way to open files for reading and writing with Python.