How do I get the modified date/time of a file in Python?
Asked
Active
Viewed 2.3k times
2 Answers
39
os.path.getmtime(filepath)
or
os.stat(filepath).st_mtime

Thomas Wouters
- 130,178
- 23
- 148
- 122
-
1@endolith: http://stackoverflow.com/a/237082/125507 says "os.path.getmtime() is made for this, and simpler." – endolith Mar 01 '12 at 15:19
20
Formated:
import time
print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname)))

Dingo
- 2,656
- 1
- 19
- 16