[BTY] Day 5: ctime() does not refer to creation time

nguyendhn

Dang Hoang Nhu Nguyen

Posted on February 9, 2022

[BTY] Day 5: ctime() does not refer to creation time

This post was for 08.02.2022

In Python, I usually retrieve ctime (means creation time for me) of a file using the following code:

from pathlib import Path
f = Path(file_path). # file_path is the path to any files in your system
file_stat = f.stat()
print(file_stat.st_ctime)
Enter fullscreen mode Exit fullscreen mode

BUT,

I've got troubles when relying on this approach, because:

ctime() does not refer to creation time on *nix systems, but rather the last time the inode data changed.

I found this from this answer: https://stackoverflow.com/a/237084/6563277

The reason is that I have modified ctime by doing something to the inode: chmod and chown on the file.

💖 💪 🙅 🚩
nguyendhn
Dang Hoang Nhu Nguyen

Posted on February 9, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

[BTY] Day 5: ctime() does not refer to creation time
betterthanyesterday [BTY] Day 5: ctime() does not refer to creation time

February 9, 2022