Sep-01-2018, 05:53 PM
A example.
String formatting used
import os path = r'E:\div_code\rename' new_path = r'E:\div_code\new' os.chdir(path) for index,img in sorted(enumerate(os.listdir(path), 1)): if img.endswith('.png'): #print(index, img) os.rename(img, f'{new_path}/{index:03}.png')See that i change to path where images are
os.chdir(path)
,if not has to use os.path.join()
in rename.String formatting used
f-string
from 3.6-->.>>> n = 5 >>> print(f'{n:03}') 005 >>> print(f'{n:08}') 00000005 >>> print(f'{n:015}') 000000000000005