Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีดูวันที่สร้างและแก้ไขไฟล์ด้วย Python

เหมือนบทความก่อนหน้า ใช้ os.path.getctime (Windows) หรือ st_birthtime (UNIX) สำหรับ creation time และ os.path.getmtime สำหรับ modification time (cross-platform)

ตัวอย่าง Windows

>>> import os
>>> print(os.path.getctime('my_file'))
1505928271.0689342

UNIX Systems

import os
stat = os.stat(path_to_file)
try:
    print(stat.st_birthtime)
except AttributeError:
    print(stat.st_mtime)

Modification Time

>>> import os
>>> print(os.path.getmtime('my_file'))
1505928275.3081832