Python os.fstat() method
Python OS file/directory methods
Overview
The os.fstat() method returns the status of the file descriptor fd, similar to stat().
Available on Unix and Windows.
The structure returned by the fstat method:
-
st_dev: Device information
-
st_ino: The file's i-node value
-
st_mode: A mask of file information containing the file's permission information and type information (whether it is a regular file, a pipe or another file type)
-
st_nlink: Number of hard links
-
st_uid: User ID
-
st_gid: Group ID
-
st_rdev: Device ID (if the file is specified)
-
st_size: File size in bytes
-
st_blksize: System I/O block size
-
st_blocks: The number of 512-byte blocks the file consists of
-
st_atime: The file's most recent access time
-
st_mtime: The file's most recent modification time
-
st_ctime: The modification time of the file status information (not the modification time of the file contents)
Syntax
The **fstat()** method syntax is as follows:
os.fstat(fd)
Parameters
-
fd -- The file descriptor.
Return Value
Returns the status of the file descriptor fd.
Example
The following example demonstrates the use of the fstat() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
# Open file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# Get tuple
info = os.fstat(fd)
print "文件信息 :", info
# Get file uid
print "文件 UID :%d" % info.st_uid
# Get file gid
print "文件 GID :%d" % info.st_gid
# Close file
os.close( fd)
The output of the above program is:
文件信息 : (33261, 3753776L, 103L, 1, 0, 0,
102L, 1238783197, 1238786767, 1238786767)
文件 UID :0
文件 GID :0