Use Python to calculate the specified directory MD5, find the same file and print according to MD5

Source: Internet
Author: User

The implementation code is as follows:

#!/usr/bin/python#*-*coding:utf8*-*import osimport sysimport hashlibdef md5sum (data):     with open (data,  "RB")  as f:         MD5 = HASHLIB.MD5 ()         for i in  f.read (4096):            if i:                 md5.update (i)              else:                 break         md5 = md5.hexdigest ()         return md5 "" " Finds the specified key in the specified dictionary, appends the value to value corresponding to the key if it exists, and saves a new element as a list if it does not exist, and the same value is saved as a list "" "Def add (Dic, key,  value):    dic.setdefaUlt (KEY, [ ]). Append (value) def _files (data):     dir = os.walk ( Data)     dic1 = {}    for x, y, z in  dir:        for i in z:             file_path = os.path.join (x, i)              add (Dic1, md5sum (File_path),  file_path)     for i in dic1:     #对字典进行循环如果有相同的文件就打印出其md5和文件名         if len (Dic1[i])  > 1:              print (I, dic1[i])     if __ name__ ==  "__main__":     _files (Sys.argv[1])


The results of the operation are as follows:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/98/5C/wKiom1k6eG2jc7JkAABbv2XTr28598.png-wh_500x0-wm_ 3-wmp_4-s_1632686050.png "title="]2f]}h7p464 ' 5_ot2vymy) m.png "alt=" wkiom1k6eg2jc7jkaabbv2xtr28598.png-wh_50 "/ >

This article is from the "Blue _ Storm" blog, make sure to keep this source http://270142877.blog.51cto.com/12869137/1933928

Use Python to calculate the specified directory MD5, find the same file and print according to MD5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.