Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách lấy stat của file bằng Python?


Để lấy stat file, dùng phương thức stat() từ module os. Thực hiện system call stat trên path. Ví dụ:

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

Hàm nhận tên file, trả về tuple 10 phần tử:

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

Dùng để interpret kết quả. Tham khảo chi tiết: https://effbot.org/zone/python-fileinfo.htm