Python-os-lstat
提供:Dev Guides
Python os.lstat()メソッド
説明
Pythonのメソッド* lstat()*はfstat()と非常によく似ており、ファイルに関する情報を返しますが、シンボリックリンクをたどりません。 これは、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/python
import os, sys
# Open a file
path = "/var/www/html/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 : (33261, 3450178L, 103L, 1, 500, 500, 0L,
1238866944, 1238866944, 1238948312)
UID of the file :500
GID of the file :500