Python os.stat() Method
os.stat() Overview
The os.stat() method is used to execute a call to system stat on the given path.
os.stat() Syntax
The stat() method syntax format is as follows.
os.stat(path)
os.stat() Parameters
- path – Specify the path
os.stat() Return Value
stat structure:
- st_mode: inode protection mode
- st_ino: inode node number.
- st_dev: The device on which the inode resides.
- st_nlink: The number of links in the inode.
- st_uid: The user ID of the owner.
- st_gid: The group ID of the owner.
- st_size: The size of the normal file in bytes; contains data waiting for some special files.
- st_atime: Time of last access.
- st_mtime: Time of last modification.
- st_ctime: The "ctime" reported by the operating system. On some systems (e.g. Unix) this is the time of the latest metadata change, on others (e.g. Windows) it is the time of creation (see the platform’s documentation for details).
os.stat() Example#1
The following example demonstrates the use of the stat() method.
#!/usr/bin/python3
import os, sys
# Show information about the file "apidemos.py"
statinfo = os.stat('apidemos.py')
print (statinfo)
Output: