10. 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:
- 10.1.
os.path— Common pathname manipulationsabspath()basename()commonprefix()dirname()exists()lexists()expanduser()expandvars()getatime()getmtime()getctime()getsize()isabs()isfile()isdir()islink()ismount()join()normcase()normpath()realpath()relpath()samefile()sameopenfile()samestat()split()splitdrive()splitext()splitunc()walk()supports_unicode_filenames
- 10.2.
fileinput— Iterate over lines from multiple input streams - 10.3.
stat— Interpretingstat()resultsS_ISDIR()S_ISCHR()S_ISBLK()S_ISREG()S_ISFIFO()S_ISLNK()S_ISSOCK()S_IMODE()S_IFMT()ST_MODEST_INOST_DEVST_NLINKST_UIDST_GIDST_SIZEST_ATIMEST_MTIMEST_CTIMES_IFSOCKS_IFLNKS_IFREGS_IFBLKS_IFDIRS_IFCHRS_IFIFOS_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_SNAPSHOT
- 10.4.
statvfs— Constants used withos.statvfs() - 10.5.
filecmp— File and Directory Comparisonscmp()cmpfiles()- 10.5.1. The
dircmpclassdircmpdircmp.report()dircmp.report_partial_closure()dircmp.report_full_closure()dircmp.leftdircmp.rightdircmp.left_listdircmp.right_listdircmp.commondircmp.left_onlydircmp.right_onlydircmp.common_dirsdircmp.common_filesdircmp.common_funnydircmp.same_filesdircmp.diff_filesdircmp.funny_filesdircmp.subdirs
- 10.6.
tempfile— Generate temporary files and directories - 10.7.
glob— Unix style pathname pattern expansion - 10.8.
fnmatch— Unix filename pattern matching - 10.9.
linecache— Random access to text lines - 10.10.
shutil— High-level file operations - 10.11.
dircache— Cached directory listings - 10.12.
macpath— Mac OS 9 path manipulation functions
See also
- Section File Objects
A description of Python’s built-in file objects.
- Module
os Operating system interfaces, including functions to work with files at a lower level than the built-in file object.
