Python Program to Get File Creation and Modification Date Using OS
# Python Program to Get File Creation and Modification Date Using OS
# importing os and time module
import os.path, time
file = pathlib.Path('test.py')
print("Last modification time: %s" % time.ctime(os.path.getmtime(file)))
print("Last metadata change time or path creation time: %s"%time.ctime(os.path.getctime(file)))
Output:
Last modification time: Tue Apr 18 10:43:24 2023
Last metadata change time or path creation time: Tue Apr 18 10:43:24 2023
Python Program to Get File Creation and Modification Date Using stat()
# Python Program to Get File Creation and Modification Date
# importing datetime and pathlib module
import datetime
import pathlib
fname = pathlib.Path('file.py')
print("Last modification time: %s" % datetime.datetime.fromtimestamp(fname.stat().st_mtime))
print("Last metadata change time or path creation time: %s" % datetime.datetime.fromtimestamp(fname.stat().st_ctime))
Output:
Last modification time: 2023-04-15 10:43:24.234189
Last metadata change time or path creation time: 2023-04-15 10:43:24.234189
About The Author
Shailendra Bramhvanshi, Founder at Techaroha Solutions Private Limited and CEO at Newtum Solutions Private Limited. BlockChain Experts with 12 years of IT Experience in of all aspects of running Organization and Project Management. I have created different coins to help the business to bring more trust. Recently deployed a stable coin in India TrueINR and working on few cryptocurrency exchanges. My Team is being rated as a top 10 blockchain service provider in India by Silicon India