zoukankan      html  css  js  c++  java
  • python对文件夹内文件去重

      昨天无聊写了一个百度图片爬虫,测试了一下搜索“斗图”。一下给我下了3000多个图片,关键是有一半以上重复的。what a fuck program !

      好吧,今天写一个文件去重功能,贴上来。

      python3.6开发,在Windows下需要安装vc2015动态库。程序已经打包好,下载地址: http://pan.baidu.com/s/1bpalugf 密码:kfk4

    #/usr/bin/env python
    #Guoyabin
    #-*- coding:utf-8 -*-
    import os,hashlib
    
    def filecount():
    	filecount=int(os.popen('dir /B |find /V /C ""').read())
    	return(filecount)
    
    def md5sum(filename):
    	f=open(filename, 'rb')
    	md5=hashlib.md5()
    	while True:
    		fb = f.read(8096)
    		if not fb:
    			break
    		md5.update(fb)
    	f.close()
    	return (md5.hexdigest())
    
    def delfile():
    	all_md5={}
    	filedir=os.walk(os.getcwd())
    	for i in filedir:
    		for tlie in i[2]:
    			if md5sum(tlie) in all_md5.values():
    				os.remove(tlie)
    			else:
    				all_md5[tlie]=md5sum(tlie)
    
    if __name__=='__main__':
    	keyword=input('
    请把本程序放到要去重的文件夹内,并按回车继续
    
    ')
    	oldf=filecount()
    	print('去重前有',oldf,'个文件
    
    
    请稍等正在为您删除重复文件...')
    	delfile()
    	print('
    
    去重后剩',filecount(),'个文件')
    	print('
    
    一共帮您删除了',oldf-filecount(),'个文件
    
    ')
    	keyword=input('请按回车退出')
    

    无耻的求一下赞助

  • 相关阅读:
    php中的heredoc和nowdoc对比
    PHP官方网站及PHP手册
    php扩展编译方法
    linux下修改时间和时区
    个人觉得非常好用的mysql客户端工具HeidiSQL
    mysql主从复制总结
    mysql优化的21条经验(转)
    mysql存储引擎选择(转)
    show profiles 分析sql耗时瓶颈
    tar命令的使用方法
  • 原文地址:https://www.cnblogs.com/guoyabin/p/6879503.html
Copyright © 2011-2022 走看看