I have 100 images in a folder and I want to rename all of them. For example, Car.1.jpg, Car.2.jpg,Car.3.jpg so on and save them into another folder. I wrote the code which renames all the images as I want but it saves in the same folder which images exist. I want to rename all images and keep the original image name in the directory and copy renamed images into another directory.
import os
from tqdm import tqdm
path = './training_data/car/'
def image_rename():
cnt = 1
for img in tqdm(os.listdir(path)):
if os.path.isfile(path+img):
filename, file_extention = os.path.splitext(path+img)
os.rename(os.path.join(path, img), os.path.join(path,
str('car.') + str(cnt) + file_extention))
cnt +=1
image_rename()