How do I get the modified date/time of a file in Python?
Asked
Active
Viewed 2.1k times
2 Answers
39
os.path.getmtime(filepath)
or
os.stat(filepath).st_mtime
Thomas Wouters
- 125,217
- 23
- 144
- 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
19
Formated:
import time
print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname)))
Dingo
- 2,486
- 1
- 18
- 14