Python os.stat()方法

Python的stat()方法在給定路徑上執行統計系統調用。

語法

以下是stat()方法的語法 -

os.rmdir(path)

參數

  • path - 這是要統計資訊是必需的路徑。

返回值

以下是stat結構的成員列表:

  • st_mode - 保護位。
  • st_ino - inode編號。
  • st_dev - 設備。
  • st_nlink - 硬鏈接數。
  • st_uid - 所有者的用戶ID。
  • st_gid - 所有者的組ID。
  • st_size - 檔大小(以位元組為單位)。
  • st_atime - 最近訪問的時間。
  • st_mtime - 最近修改內容的時間。
  • st_ctime - 最近元數據更改的時間。

示例

以下示例顯示了stat()方法的用法。

# !/usr/bin/python3
import os, sys

# showing stat information of file "foo.txt"
statinfo = os.stat('foo.txt')

print (statinfo)

當運行上述程式時,它會產生以下結果 -

os.stat_result(st_mode = 33206, st_ino = 281474976797706,
   st_dev = 1017554828, st_nlink = 1, st_uid = 0, st_gid = 0,
   st_size = 13, st_atime = 1455649253, st_mtime = 1438077266, st_ctime = 1455560006)

上一篇: Python os模組方法 下一篇: Python異常處理