To get the file modification date/time we have many methods some of them are as follows:-
The first method you can use the os.path.getmtime and os.path.getctime functions:-
import os.path, time
print("last modified: %s" % time.ctime(os.path.getmtime(file)))
print("created: %s" % time.ctime(os.path.getctime(file)))
Another important method is to use os.stat:
import os, time
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
print("last modified: %s" % time.ctime(mtime))
The important point to note here is the ctime() does not refer to creation time on the system but rather the last time the inode data changed.
For more information, kindly refer to our Python course.