I have over 2000 images in a folder that needs to be renamed. Currently, it's a default name as w=0&h=-_BACl339n_c4PTZDlVgaHWg9s1k_Vyz8PbhNhhXkQk=0
and I need it to name it as fear_1
and all the other images in this format. Is there any way to achieve this?
Asked
Active
Viewed 617 times
-1

The Singularity
- 2,428
- 3
- 19
- 48

Waseq
- 1
-
Yes. Have you tried searching for similar posts? [Rename multiple files in Python](https://stackoverflow.com/questions/17748228/rename-multiple-files-in-python), [Renaming multiple files in a directory using Python](https://stackoverflow.com/q/37467561/2745495), etc. – Gino Mempin Oct 17 '21 at 11:03
1 Answers
1
Use os.listdir
to get all the filenames and os.rename
to rename them
import os
path = '//path//to//folder'
files = os.listdir(path)
for index, file in enumerate(files):
os.rename(os.path.join(path, file), os.path.join(path, ''.join(['fear_',str(index+1), '.jpg'])))

kinshukdua
- 1,944
- 1
- 5
- 15