[Python] Get all pictures in a directory (sorted by picture name)

import os
img_folder = ''
img_list = [os.path.join(img_folder, nm) for nm in os.listdir(img_folder) if nm[-3:] in ['jpg','png','gif']]
img_list.sort()

Picture suggest that you named when not simply use a single number, so that the picture sort sorting time, there will be 11.jpgranked in 2.jpgfront of the
suggested adding zfill()the above-mentioned problems to avoid ordering

idx = 1
img_name = str(idx).zfill(3)+'.jpg'

Will get001.jpg

Guess you like

Origin blog.csdn.net/weixin_38705903/article/details/106521371