Image.open() 批量获取图片尺寸
判断 是否满足:高 <= 1000 和 宽 >= 1000
shutil.copy(, ) 批量复制到指定路径
import os
import shutil
from PIL import Image
def file_name(file_path):
path=os.listdir(file_path)
return path
# srcfile 需要复制、移动的文件
# dstpath 目的地址
def mycopyfile(srcfile,dstpath): # 复制函数
if not os.path.isfile(srcfile):
print ("%s not exist!"%(srcfile))
else:
fpath,fname=os.path.split(srcfile) # 分离文件名和路径
if not os.path.exists(dstpath):
os.makedirs(dstpath) # 创建路径
shutil.copy(srcfile, dstpath + fname) # 复制文件
# shutil.move(srcfile, dstpath + fname) # 移动文件
print ("copy %s -> %s"%(srcfile, dstpath + fname))
if __name__ == "__main__":
print('start')
path = "D:\\z次元岛-图集10-20\\" #原地址
copy_path = path+"壁纸1\\" # 目的地址
# filename = "D:\\z次元岛-图集1-10\\112879-210R6113224.jpg"
for each in file_name(path):
each = path+each
# height=file_height(each)
try:
img = Image.open(each)
except:
pass
if img.height <= 1000 and img.width >= 1000:
mycopyfile(each,copy_path)
print('finall')