Image rename 1

 avatar
PEGG
python
4 days ago
667 B
0
Indexable
Never
import os

def rename_images(folder_path,num,prefix):

 files = os.listdir(folder_path)
 image_files = [f for f in files if f.endswith('.jpg') or f.endswith('.jpeg') or f.endswith('.png')]

 c=num
 for filename in (image_files):

  new_filename = f'{prefix}{c}.jpg'

  os.rename(os.path.join(folder_path, filename), os.path.join(folder_path, new_filename))

  print(f'Renamed {filename} to {new_filename}')

  c+=1

path = input("enter the folder path\n")
cleaned_path=path.replace('"','')
prefix=input("enter the prefix\n")
number =int(input("enter the starting number\n"))
folder_path = cleaned_path
rename_images(folder_path,number,prefix)
Leave a Comment