-1

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?

1

1 Answer 1

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'])))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.