w3resource

Python: Get file creation and modification date/times

Python Basic: Exercise-64 with Solution

Write a Python program to get file creation and modification date/times.

Sample Solution :-

Python Code :

import os.path, time
print("Last modified: %s" % time.ctime(os.path.getmtime("test.txt")))
print("Created: %s" % time.ctime(os.path.getctime("test.txt")))

Sample Output:

Last modified: Wed Apr 19 11:36:23 2017                                                                       
Created: Wed Apr 19 11:36:23 2017 

Flowchart:

Flowchart: Get file creation and modification date/times.

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to get an absolute file path.
Next: Write a Python program to convert seconds to day, hour, minutes and seconds.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Try-catch-else construct:

try:
  foo() 
except Exception: 
  print("Exception occured")
else:
  print("Exception didnt occur")
finally:
  print("Always gets here")