How to get the creation date of a file using Python

The creation date of a fileis accessed using the os.path and time libraries.

Syntax:

import os.path, time

time.ctime(os.path.getctime("test.txt"))

This code example accesses the time of the test.txt file using the os.path library. That time is formatted using the time module. The resulting string is written in the output for rendering.

import os.path, time

print("created: %s" % time.ctime(os.path.getctime("test.txt")))

The output will be:

$ py test.py
created: Wed Jul  4 14:42:37 2018

References:

Python

Share this article:

Recent Comments