Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import hashlib
- def search_file(dir_name = ''):
- ' 扫描目录、删除重复文件 '
- file_path = []
- for path in os.walk(dir_name):
- for file in path[2]:
- file_path.append(path[0] + '\\' + file)
- return file_path
- def generate_md5(content):
- ' 生成MD5 '
- md5 = hashlib.md5(content)
- return md5.hexdigest()
- def check_del(file_lst = []):
- md5_lst = []
- for file in file_lst:
- print('Check', file)
- f = open(file, 'rb')
- md5 = generate_md5(f.read(1024))
- f.close()
- if md5 in md5_lst:
- os.remove(file)
- print('Delete!')
- continue
- md5_lst.append(md5)
- if __name__ == '__main__':
- check_del(search_file(r' Target folder '))
Add Comment
Please, Sign In to add comment