How do I get the modified date/time of a file in Python? [duplicate]
Asked Answered
S

2

23

How do I get the modified date/time of a file in Python?

Seaddon answered 23/9, 2008 at 13:34 Comment(0)
P
39
os.path.getmtime(filepath)

or

os.stat(filepath).st_mtime
Perceptive answered 23/9, 2008 at 13:35 Comment(1)
@endolith: https://mcmap.net/q/45386/-how-do-i-get-file-creation-and-modification-date-times says "os.path.getmtime() is made for this, and simpler."Rowden
L
20

Formated:

import time
print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname)))
Lozada answered 24/5, 2011 at 12:6 Comment(1)
ISO-like fmt: "%Y-%m-%d %I:%M:%S %p"Sharp

© 2022 - 2024 — McMap. All rights reserved.