如何使用 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 月 3 日

221 次瀏覽

啟動你的職業

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.