我怎樣才能使用 Python 獲取檔案的許可權掩碼?


若要獲取檔案的統計資訊,可以使用 os 模組中的 stat() 方法。它對給定路徑執行 stat 系統呼叫。例如,

import os
st = os.stat("file.dat")

此函式獲取檔名,並返回包含以下內容的 10 個成員的元組

(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)

mode 變數向你提供有關檔案許可權的資訊。你可以透過 st[0] 獲取它。你可以在此處閱讀有關解釋元組的更多資訊:http://effbot.org/zone/python-fileinfo.htm

更新日期:2019 年 10 月 03 日

223 次瀏覽

開啟你的 職業生涯

完成課程並透過認證

開始
廣告
© . All rights reserved.