解决方案:
方案1:
https://blog.csdn.net/qq_22227123/article/details/79903116
方案2:
https://blog.csdn.net/cdw_FstLst/article/details/50009203
可以参考的code
import os
dataPath = r'D:\KerasProject\CTALabelDatdMatForHuang\test'
print(dataPath)
allName = os.listdir(dataPath)
allTestDataName = []
for filename in os.listdir(dataPath):
if filename.endswith('.png') and not('pre' in filename):#文件名中不包含'pre'字符串
#print(filename)
allTestDataName.append(filename)
allTestDataName.sort(key= lambda x:int(x[:-4]))
print(allTestDataName)