# coding=utf-8 import os import shutil import os.path def get_size(path_in,path_out): fileList = os.listdir(path_in) # 获取path目录下所有文件 for filename in fileList: pathTmp = os.path.join(path_in,filename) # 获取path与filename组合后的路径 if os.path.isdir(pathTmp): # 判断是否为目录 get_size(pathTmp,path_out) # 是目录就继续递归查找 elif os.path.isfile(pathTmp): # 判断是否为文件 filesize = os.path.getsize(pathTmp) # 如果是文件,则获取相应文件的大小 print('目录中的子文件大小:%d字节' % filesize) if filesize > 10240: if pathTmp.endswith('gif'): shutil.copyfile(pathTmp, os.path.join(path_out, filename)) else : shutil.copyfile(pathTmp, os.path.join(path_out,filename) + '.gif') #path= input("输入路径:").strip() #由用户指定文件路径 path_in = 'C:\Users\xxx\Desktop\img' path_out = 'd:\img' get_size(path_in,path_out)