Windows File Creation Time Setter

1.2.0 · active · verified Thu Apr 09

win32-setctime is a small Python utility designed to set the creation time (ctime) of files and directories on Windows operating systems. It currently is at version 1.2.0 and has an infrequent, but active, release cadence, with updates typically addressing bug fixes, accuracy improvements, or new features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a file, then use `setctime` to modify its creation timestamp to a specific point in time (in this case, one day in the past).

import os
import time
from datetime import datetime
from win32_setctime import setctime

# Create a dummy file
file_path = 'my_test_file.txt'
with open(file_path, 'w') as f:
    f.write('Hello, world!')

# Get current timestamp
current_timestamp = time.time()
print(f"Current file creation time: {datetime.fromtimestamp(os.path.getctime(file_path))}")

# Set a new creation time (e.g., 1 day in the past)
new_timestamp = current_timestamp - (24 * 60 * 60)
setctime(file_path, new_timestamp)

print(f"New file creation time: {datetime.fromtimestamp(os.path.getctime(file_path))}")

# Clean up
os.remove(file_path)

view raw JSON →