find the creation date of a directory in python

You can use the os.path.getctime() method to get the creation time of a directory in Python. This method returns the timestamp of the creation time of the file or directory in seconds since the epoch. You can then convert this timestamp to a readable format using the datetime module.

Here's an example code snippet that demonstrates how to find the creation date of a directory in Python:

main.py
import os
import datetime

path = '/path/to/directory'

# Get the creation time of the directory
creation_time = os.path.getctime(path)

# Convert the creation time to a readable format
created_at = datetime.datetime.fromtimestamp(creation_time)

# Print the creation time in a formatted string
print(f"Directory '{path}' was created on {created_at}")
352 chars
14 lines

Replace /path/to/directory with the actual path of the directory you want to check. The code will print the creation time of the directory in the following format:

Directory '/path/to/directory' was created on YYYY-MM-DD HH:MM:SS.ssssss.

gistlibby LogSnag