lstat() 方法非常相似於fstat()方法,它返回包含有關檔資訊的 stat_result 對象, 但不遵循符號鏈接。這是fstat()的別名,不支持符號鏈接,如在 Windows 平臺。
下麵是 lstat() 方法返回的結構:
-
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: 狀態最後一次修改的時間
語法
以下是 lstat() 方法的語法:
os.lstat(path)
參數
-
path -- 這是將返回資訊的檔。
返回值
此方法返回有關檔的資訊。
示例
下麵的示例顯示 lstat() 方法的使用。
#!/usr/bin/python3 import os, sys # Open a file path = "d:\\python3\\foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT ) # Close opened file os.close( fd ) # Now get the touple info = os.lstat(path) 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)
當我們運行上面的程式,它會產生以下結果:
File Info : os.stat_result(st_mode=33206, st_ino=281474976797706, st_dev=1017554828, st_nlink=2, st_uid=0, st_gid=0, st_size=13, st_atime=1455597777, st_mtime=1438077266, st_ctime=1455560006) UID of the file :0 GID of the file :0
上一篇:
Python3檔方法
下一篇:
Python3 os檔目錄的方法