从文件夹及其子文件夹批量读取图像
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 28 09:03:51 2020
@author: xiang
"""
#把path文件夹下以及其子文件下的所有png图片移动(不是复制)
import os
import shutil
path = 'D:/下载/CASIA-Iris-Distance' #原始路径
new_path = 'D:/下载/casia_hongwai' #新文件路径
for root, dirs, files in os.walk(path):
if len(dirs) == 0:
for i in range(len(files)):
if files[i][-3:] == 'jpg': #可把‘jpg’改为其他
file_path = root+'/'+files[i]
new_file_path = new_path+ '/'+ files[i]
shutil.move(file_path,new_file_path)
备注:本人小白,本文内容若有不妥之处,欢迎批评指正!