Python3 os.stat() Method
Python3 OS File/Directory Methods
Overview
The os.stat() method is used to perform a system stat call on the given path.
Syntax
stat()The method syntax is as follows:
os.stat(path)
Parameters
path-- specified path
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: Number of links to the inode.
- st_uid: User ID of the owner.
- st_gid: Group ID of the owner.
- st_size: Size of a regular file in bytes; includes data waiting for certain special files.
- st_atime: Time of last access.
- st_mtime: Time of last modification.
- st_ctime: "ctime" reported by the operating system. On some systems (such as Unix) it is the time of the latest metadata change, on other systems (such as Windows) it is the creation time (see the platform documentation for details).
Example
The following example demonstrates the use of the stat() method:
#!/usr/bin/python3
import os, sys
# 显示文件 "a2.py" 信息
statinfo = os.stat('a2.py')
print (statinfo)
The output of the above program is:
posix.stat_result(st_mode=33188, st_ino=3940649674337682L, st_dev=277923425L, st _nlink=1, st_uid=400, st_gid=401, st_size=335L, st_atime=1330498089, st_mtime=13 30498089, st_ctime=1330498089)Other Extensions