Python-os-stat

提供:Dev Guides
移動先:案内検索

Python os.stat()メソッド

説明

Pythonメソッド* stat()*は、指定されたパスでstatシステムコールを実行します。

構文

以下は、* stat()*メソッドの構文です-

os.stat(path)

パラメーター

  • path -これは統計情報が必要なパスです。

戻り値

ここにstat構造体のメンバーのリストがあります-

  • st_mode -保護ビット。
  • st_ino -iノード番号。
  • st_dev -デバイス。
  • st_nlink -ハードリンクの数。
  • st_uid -所有者のユーザーID。
  • st_gid -所有者のグループID。
  • st_size -バイト単位のファイルのサイズ。
  • st_atime -最新のアクセス時刻。
  • st_mtime -最新のコンテンツ変更の時刻。
  • st_ctime -最新のメタデータ変更の時刻。

次の例は、stat()メソッドの使用法を示しています。

# !/usr/bin/python

import os, sys

# showing stat information of file "a2.py"
statinfo = os.stat('a2.py')

print statinfo

上記のプログラムを実行すると、次の結果が生成されます-

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)