Python os.stat() 方法
概述
os.stat() 方法用於在給定的路徑上執行一個系統 stat 的調用。
語法
stat()方法語法格式如下:
os.stat(path)
參數
path -- 指定路徑
返回值
stat 結構:
- st_mode: inode 保護模式
- st_ino: inode 節點號。
- st_dev: inode 駐留的設備。
- st_nlink: inode 的鏈接數。
- st_uid: 所有者的用戶ID。
- st_gid: 所有者的組ID。
- st_size: 普通檔以位元組為單位的大小;包含等待某些特殊檔的數據。
- st_atime: 上次訪問的時間。
- st_mtime: 最後一次修改的時間。
- st_ctime: 由操作系統報告的"ctime"。在某些系統上(如Unix)是最新的元數據更改的時間,在其他系統上(如Windows)是創建時間(詳細資訊參見平臺的文檔)。
實例
以下實例演示了 stat() 方法的使用:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 顯示檔 "a2.py" 資訊 statinfo = os.stat('a2.py') print statinfo
執行以上程式輸出結果為:
posix.stat_result(st_mode=33188, st_ino=3940649674337682L, st_dev=277923425L, st _nlink=1, st_uid=400, st_gid=401, st_size=335L, st_atime=1330498089, st_mtime=13 30498089, st_ctime=1330498089)