Python3-os-lstat
提供:Dev Guides
Python 3-os.lstat()メソッド
説明
メソッド* lstat()はfstat()と非常によく似ており、ファイルに関する情報を含む *stat_result オブジェクトを返しますが、シンボリックリンクをたどりません。 これは、Windowsなどのシンボリックリンクをサポートしないプラットフォームでのfstat()のエイリアスです。
これはlstatメソッドによって返される構造です-
- 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 -最後のステータス変更の時間
構文
以下は* lstat()*メソッドの構文です-
os.lstat(path)
パラメーター
パス-これは、情報が返されるファイルです。
戻り値
このメソッドは、ファイルに関する情報を返します。
例
次の例は、lstat()メソッドの使用法を示しています。
#!/usr/bin/python3
import os, sys
# Open a file
path = "d:\\python3\\foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close opened file
os.close( fd )
# Now get the touple
info = os.lstat(path)
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)
結果
上記のプログラムを実行すると、次の結果が生成されます-
File Info : os.stat_result(st_mode=33206, st_ino=281474976797706, st_dev=1017554828, st_nlink=2, st_uid=0, st_gid=0, st_size=13, st_atime=1455597777, st_mtime=1438077266, st_ctime=1455560006)
UID of the file :0
GID of the file :0