文件去重,文件,__author__ =
文章由Byrx.net分享于2019-03-23 04:03:36
文件去重,文件,__author__ =
__author__ = 'lixin'import osfrom shutil import *from hashlib import md5import datetimeimport timeimport randomtargetPath='H:\\temp\\pic\\'srcPath=['H:\\image\\','H:\\kp\\']dstPath='H:\\temp\\dstPic'filekey={}year={}def md5_file(name): m=md5() a_file=open(name,'rb') m.update(a_file.read()) a_file.close() return m.hexdigest()def dofile(arg,dir,names): for name in names: subname=os.path.join(dir,name) if os.path.isdir(subname): continue if not os.path.exists(subname): continue key=md5_file(subname) if not filekey.has_key(key): filekey[key]=subname print 'file ok:',subname continue if os.path.exists(os.path.join(dstPath,name)): name=''.join(name.split('.')[:-1])+str(random.randint(1,100))+'.'+name.split('.')[-1] copy2(subname,os.path.join(dstPath,name)) os.remove(subname) print 'remove',subnamefor path in srcPath: os.path.walk(path,dofile,'')
相关内容
- python解析网页的字符编码,python解析字符,import urlli
- python密码生成器,python生成器,python密码生成器,
- 基于Selenium的用户登录自动化测试用例,selenium用例,#
- 分享一个metasploit快速测试脚本的TIPS,metasploittips,相信
- 用Python杀掉windows平台下的进程,pythonwindows,# "这段代
- Python 生成随机密码,python生成,import strin
- Python将阿拉伯数字转化为中文大写,python阿拉伯,利用
- 用 python 实现各种排序算法,python算法,总结了一下常见
- python生成图片,,import cv2.c
- Python实现登录人人网并抓取新鲜事的方法,python新鲜事
评论关闭