Python os.stat() method
Python OS file/directory methods
Overview
The os.stat() method performs a system stat call on the given path.
Syntax
The **stat()** method syntax is as follows:
os.stat(path)
Parameters
-
path -- The specified path
Return Value
The stat structure:
- **st_mode: ** inode protection mode
- **st_ino: ** inode 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; contains the amount of data pending for certain 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 (such as Unix) it is the time of the most recent metadata change; on others (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/python
# -*- coding: UTF-8 -*-
import os, sys
# Show information about file "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)