Python os.stat() Method

Python File(文件) 方法Python OS File/Directory Methods


Overview

The os.stat() method performs 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: Device on which the inode resides.
  • st_nlink: Number of links to the inode.
  • st_uid: Owner's user ID.
  • st_gid: Owner's group ID.
  • st_size: The size of a regular file in bytes; contains 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, while on other systems (such as Windows) it is the creation time (see the platform's documentation for details).

Example

The following example demonstrates the use of the stat() method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

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)

Python File(文件) 方法Python OS File/Directory Methods

Other Extensions