When users provide a path you really don't know what the path refers to. Is it a file? Is it a directory? Does it even exist?
Retrieving file information allows us to fetch details about the provided path, such as whether it points to a file and how big that file is.
Perform the following steps for this recipe:
- Using
.stat()
on anypathlib.Path
will provide most details about a path:
>>> pathlib.Path('conf.py').stat()
os.stat_result(st_mode=33188,
st_ino=116956459,
st_dev=16777220,
st_nlink=1,
st_uid=501,
st_gid=20,
st_size=9306,
st_atime=1519162544,
st_mtime=1510786258,
st_ctime=1510786258)
The returned details refer to:
st_mode
: File type, flags, and permissionsst_ino
: Filesystem node storing the filest_dev
: Device where the file is storedst_nlink
: Number of references (hyperlinks) to this filest_uid
:...