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文件目录的方法