Python3 os.fstat()方法

fstat()方法返回關於與 fd 相關的檔資訊。下麵是 fstat 方法返回結構:
  • st_dev: 包含設備檔的標識

  • st_ino: inode編號

  • 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/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

上一篇: Python3檔方法 下一篇: Python3 os檔目錄的方法