Daily Python Projects

Daily Python Projects

Share this post

Daily Python Projects
Daily Python Projects
Python Project: Rename Text Files with Today's Date
Copy link
Facebook
Email
Notes
More

Python Project: Rename Text Files with Today's Date

Level: Real-World Project

May 09, 2025
∙ Paid
4

Share this post

Daily Python Projects
Daily Python Projects
Python Project: Rename Text Files with Today's Date
Copy link
Facebook
Email
Notes
More
Share

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.

This post is for paid subscribers

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

Share

Copy link
Facebook
Email
Notes
More