Assuming the file exists (using os.path.exists(filename) to first make sure that it does), how do I display the time a file was last modified? This is on Linux if that makes any difference.
3 Answers
import os filename = "/etc/fstab" statbuf = os.stat(filename) print("Modification time: {}".format(statbuf.st_mtime)) Linux does not record the creation time of a file (for most fileystems).
Comments
New for python 3.4+ (see: pathlib)
import pathlib path = pathlib.Path('some/path/to/file.ext') last_modified = path.stat().st_mtime