Python os.fstat () method
Python OS file / directory methods
Outline
os.fstat () method returns the file descriptor fd state, similar to the stat ().
Unix, is available on Windows.
fstat method returns a structure:
st_dev: Device Information
st_ino: i-node value file
st_mode: file mask information, including information about file permissions, file type information (ordinary file or pipe file, or other file types)
st_nlink: Hard connection
st_uid: User ID
st_gid: User Group ID
st_rdev: Device ID (if the specified file)
st_size: file size in byte units
st_blksize: system I / O block size
st_blocks: the file is the number of 512 byte blocks constituted by the
st_atime: Recent File access time
st_mtime: file last modification time
st_ctime: Modified file status information (not the contents of the file modification time)
grammar
fstat () method syntax is as follows:
os.fstat(fd)
parameter
fd - the file descriptor.
return value
Returns the file descriptor fd state.
Examples
The following example demonstrates fstat () method of use:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 获取元组 info = os.fstat(fd) print "文件信息 :", info # 获取文件 uid print "文件 UID :%d" % info.st_uid # 获取文件 gid print "文件 GID :%d" % info.st_gid # 关闭文件 os.close( fd)
The above program output is:
文件信息 : (33261, 3753776L, 103L, 1, 0, 0, 102L, 1238783197, 1238786767, 1238786767) 文件 UID :0 文件 GID :0