Name Picture with python - specific pattern

22 Views Asked by At

I want to change the name of the pictures I took. It should look like this after:

  • 20200701_Foto_1.1.jpg
  • 20200701_Foto_1.2.jpg
  • 20200701_Foto_1.3.jpg
  • 20200701_Foto_PB1.jpg
  • 20200701_Foto_2.1.jpg
  • 20200701_Foto_2.2.jpg
  • 20200701_Foto_2.3.jpg
  • 20200701_Foto_PB2.jpg
  • ...

The code written down here does not work and I don't know how to write it differently. Does someone of you have an idea ? :-)

Looking forward reading you!

import os
from natsort import natsorted

datum = 20200701
os.chdir('/Users/Aka/Desktop/'+datum+'_Fotos_rawdata Kopie')
for i in enumerate(natsorted(os.listdir('/Users/Aka/Desktop/'+datum+'_Fotos_rawdata Kopie'))):
    for j in (1,4):
        if j ==1 or j==2 or j==3:
            os.rename(datum+"_Foto_",i+"."+j,".jpg")
        if j ==4:
            os.rename(datum+"_Foto_PB",i,".jpg")
0

There are 0 best solutions below