import numpy as np
import os
img_path='./img/'
 
img_list=os.listdir(img_path)
img_list.sort()
img_list.sort(key = lambda x: int(x[:-4])) ##文件名按数字排序
img_nums=len(img_list)
for i in range(img_nums):
    img_name=img_path+img_list[i]
    print(img_name)

参考:https://www.jb51.net/article/195514.htm