image rename 2

 avatar
PEGG
python
10 days ago
477 B
1
Indexable
Never
import os

name = "test1"
directory=r"D:\test1"

prefix="Etest_"

files = os.listdir(directory)

c=152

if os.path.basename(directory) == name:
 for filename in files:
  if filename.endswith('.jpg') or filename.endswith('.png') or filename.endswith('.jpeg'):
   newfilename= f"{prefix}{c}.jpg"
   old=os.path.join(directory,filename)
   new=os.path.join(directory,newfilename)

  os.rename(old,new)

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

  c+=1
Leave a Comment