Can explain in more detail and also do a test Linux(Mint 19).
import os path = '/home/tom/Documents/py_files/rename' new_path = '/home/tom/Documents/py_files/new_names' 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')in folder rename(also the images i want to rename):
image_1.png image_2.png image_3.png image_4.pngRunning this need 3.6 or newer 3.7.
# Check python 3 version tom@tom-VirtualBox:~/Documents/py_files$ python3 -V Python 3.6.5 # Run with python3 tom@tom-VirtualBox:~/Documents/py_files$ python3 rename.pyNow in folder new_names:
Output:001.png
002.png
003.png
004.png
Quote:can you tell what does the following lines mean?It's string formatting f-string:
>>> new_path = 'foo' >>> index = 9 >>> print(f'{new_path}/{index:03}.png') foo/009.png