23

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

0

2 Answers 2

39
os.path.getmtime(filepath)

or

os.stat(filepath).st_mtime
Sign up to request clarification or add additional context in comments.

1 Comment

@endolith: stackoverflow.com/a/237082/125507 says "os.path.getmtime() is made for this, and simpler."
20

Formated:

import time
print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname)))

1 Comment

ISO-like fmt: "%Y-%m-%d %I:%M:%S %p"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.