Daily Python Projects

Daily Python Projects

Python Project: Rename Text Files with Today's Date

Level: Real-World Project

Ardit Sulce's avatar
Ardit Sulce
May 09, 2025
∙ Paid

Project Overview 💡

In this project, you’ll write a Python script that appends the current date to all .txt filenames in a specified folder. This is useful for version control, organizing files by date, or backing up daily logs.


Challenge Yourself! 🚀

Before checking the solution, try building a script that scans a folder and renames each .txt file by adding today's date at the end.

Task:

Write a Python program that:

  • Goes through each .txt file in a directory

  • Appends the current date to the filename
    For example, file a.txt should be renamed to a-2025-5-8.txt (existing_name-YYYY-MM-DD.txt)

  • You can download and use these sample files and place them in a directory named “files”.

Expected Output:
The console will display the old and new names of each file.

And here is how the renamed files look like:

Give it a shot! Scroll down when you're ready for the step-by-step guide.









Spoiler Alert!








Step-by-Step Guide

Step 1️⃣: Import Required Modules

We’ll use os for working with files and datetime for getting the current date.

import os
from datetime import datetime

Step 2️⃣: Set the Target Directory

Specify the directory where your .txt files are stored.

Keep reading with a 7-day free trial

Subscribe to Daily Python Projects to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Ardit Sulce · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture