import random
import os
def file_name(file_dir):
L=[]
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == '.jpg':
#L.append(os.path.join(root, file))
L.append(file)
return L
my_filename=file_name('D:\\Images')
random.shuffle(my_filename)
f=open('demo.txt','w')
for i in my_filename:
#k=' '.join([str(j) for j in i])
f.write(i+"\n")
f.close()
Python实例1-读取指定文件夹下指定类型的图片名,打乱后输出txt
最新推荐文章于 2022-09-18 10:40:24 发布