Function:
os.stat(path, *, dir_fd=None, follow_symlinks=True)
Overview:
- The function os.stat() returns information about a file returned as a os.stat_result object. The attributes of the os.stat_result and their meanings are given below:
Attribute |
Description |
st_mode |
Type and mode of the file. |
st_ino |
The index count of the inode that holds the information on the file. In Unix like operating systems, an inode is a data structure that holds storage block location and other attributes of the file. |
st_dev |
Name of the device where the file is present. Using the function os.major() and os.minor(), major and minor device numbers can be found. |
st_nlink |
Number of hard links to the file. |
st_uid |
User id. |
st_gid |
Group id. |
st_size |
Size of the file in bytes. |
st_atime |
Time the file was accessed last. |
st_mtime |
Time the file was modified last. |
st_ctime |
Time of the last status change of the file. |
Parameters:
path - File path for which information is needed.
dir_fd - Optional parameter. If provided the path is considered relative to the directory as represented by the descriptor.
follow_symlinks - Optional parameter. If the path points to a symbolic link, the follow_symlinks flag resolves with the link itself or to the actual file pointed to.
Return Value:
An object of type os.stat_result.
Example:
# Example Python program that provides information about a file using the # File path # Get file information # Print file information print("===Storage related:===") deviceNum = stats.st_dev print("Device id:%d"%deviceNum) print("===User & Group:===") print("===Time Related:===")
|
Output:
Statistics for the file /ex/Wheels.txt: |