Python3-os-fstat

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

Python 3-os.fstat()メソッド

説明

メソッド* fstat()*は、fdに関連付けられたファイルに関する情報を返します。 これは、fstatメソッドによって返される構造です-

  • st_dev -ファイルを含むデバイスのID
  • st_ino -iノード番号
  • st_mode -保護
  • st_nlink -ハードリンクの数
  • st_uid -所有者のユーザーID
  • st_gid -所有者のグループID
  • st_rdev -デバイスID(特殊ファイルの場合)
  • st_size -合計サイズ、バイト単位
  • st_blksize -ファイルシステムI/Oのブロックサイズ
  • st_blocks -割り当てられたブロックの数
  • st_atime -最終アクセス時刻
  • st_mtime -最終変更時刻
  • st_ctime -最後のステータス変更の時間

構文

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

os.fstat(fd)

パラメーター

*fd* -これは、システム情報が返されるファイル記述子です。

戻り値

このメソッドは、fdに関連付けられているファイルに関する情報を返します。

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

#!/usr/bin/python3
import os, sys

# Open a file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# Now get  the touple
info = os.fstat(fd)
print ("File Info :", info)

# Now get uid of the file
print ("UID of the file :%d" % info.st_uid)

# Now get gid of the file
print ("GID of the file :%d" % info.st_gid)

# Close opened file
os.close( fd)

結果

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

File Info : os.stat_result(st_mode=33206, st_ino=2533274790483933, st_dev=1017554828, st_nlink=1, st_uid=0, st_gid=0, st_size=61, st_atime=1455562034, st_mtime=1455561637, st_ctime=1455561164)
UID of the file :0
GID of the file :0