python打乱文件夹下所有图片
import random
import os
Big_Image_path = r"D:\ML\images\leaf_enhance\leaf_image"
foldres = os.listdir(Big_Image_path)
print(foldres)
for dirname in foldres:
small_Image_path = Big_Image_path + '/' + dirname
files = os.listdir(small_Image_path)
Imgnum = len(files)
L = random.sample(range(0, Imgnum), Imgnum)
print(L)
filetype = ".jpg"
i = 0
for filename in files:
portion = os.path.splitext(filename)
if portion[1] == filetype:
newname = str(L[i]) + filetype
print(newname)
os.rename(small_Image_path + '/' + filename, small_Image_path + '/' + newname)
i = i + 1