Python方法lstat()与fstat()非常相似,并返回有关文件的信息,但不遵循符号链接。这是不支持符号链接的平台(如Windows)上fstat()的别名。
下面是lstat方法-返回的结构
st_dev - 包含文件的设备的ID
st_ino - 信息节点编号
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 - 上次状态更改的时间
os.lstat(path)
path - 这是将返回其信息的文件。
此方法返回有关文件的信息。
以下示例显示了lstat()方法的用法。
#!/usr/bin/python import os, sys # 打开文件 path="/var/www/html/foo.txt" fd=os.open( path, os.O_RDWR|os.O_CREAT ) # 关闭已打开的文件 os.close( fd ) # Now get the touple info=os.lstat(path) print "File Info :", info # 现在得到文件的UID print "UID of the file :%d" % info.st_uid # 现在获取文件的GID 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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)