Creation (change) time of a file

EasyOS Module Programs · 44 of 49

Write a Python program to get the ctime of a file with os.path.getctime().

Advertisement
Output
float
True

Approach

  1. The result is a timestamp; format it with datetime.

Solution

Python
import osfrom datetime import datetime open("timed.txt", "w").close()ctime = os.path.getctime("timed.txt")print(type(ctime).__name__)print(datetime.fromtimestamp(ctime).date() == datetime.now().date())
Output
float
True
Note

On Windows ctime is the creation time; on Linux it is the last metadata change.

Learn the concept

New to this topic? Read the lesson, then come back.

More os module programs

← All 49 OS Module Programs

Leave a Comment