Python-os-fstat
提供:Dev Guides
Python os.fstat()メソッド
説明
Pythonメソッド* 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に関連付けられているファイルに関する情報を返します。
例
次の例は、chdir()メソッドの使用法を示しています。
#!/usr/bin/python
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 : (33261, 3753776L, 103L, 1, 0, 0,
102L, 1238783197, 1238786767, 1238786767)
UID of the file :0
GID of the file :0