Source Code ⌨️ Automate File Renaming with Python

Currently reading:
 Source Code ⌨️ Automate File Renaming with Python

viha24

Member
LV
0
Joined
Jun 28, 2024
Threads
2
Likes
0
Awards
1
Credits
306©
Cash
0$

Tired of renaming files one by one? Let's automate it with Python!

💡 Save time and avoid repetitive tasks with this simple script!
Python:
import os

# https://t.me/LearnPython3

directory = 'path/to/your/folder'
prefix = 'image_'

# Iterate over files in the directory
for count, filename in enumerate(os.listdir(directory)):
    new_name = f"{prefix}{count}.png"
    src = f"{directory}/{filename}"
    dst = f"{directory}/{new_name}"
    
    # Rename the file
    os.rename(src, dst)
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Top Bottom