Python3-os-stat
提供:Dev Guides
Python 3-os.stat()メソッド
説明
メソッド* 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/python3
import os, sys
# showing stat information of file "foo.txt"
statinfo = os.stat('foo.txt')
print (statinfo)
結果
上記のプログラムを実行すると、次の結果が生成されます-
os.stat_result(st_mode = 33206, st_ino = 281474976797706,
st_dev = 1017554828, st_nlink = 1, st_uid = 0, st_gid = 0,
st_size = 13, st_atime = 1455649253, st_mtime = 1438077266, st_ctime = 1455560006)