Python3 os.lstat() 方法
概述
os.lstat() 方法用於類似 stat() 返回檔的資訊,但是沒有符號鏈接。在某些平臺上,這是fstat的別名,例如 Windows。
語法
lstat()方法語法格式如下:
os.lstat(path)
參數
path -- 要返回資訊的檔。
返回值
返回檔資訊。
實例
以下實例演示了 lstat() 方法的使用:
#!/usr/bin/python3
import os, sys
# 打開檔
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# 關閉打開的檔
os.close( fd )
# 獲取元組
info = os.lstat(path)
print ("檔資訊 :", info)
# 獲取檔 uid
print ("檔 UID :%d" % info.st_uid)
# 獲取檔 gid
print ("檔 GID :%d" % info.st_gid)
執行以上程式輸出結果為:
檔資訊 : (33261, 3450178L, 103L, 1, 500, 500, 0L,
1238866944, 1238866944, 1238948312)
檔 UID :500
檔 GID :500

Python3 OS 檔/目錄方法