python 查找目录中的重复文件脚本

!/usr/bin/python

coding=utf-8

from hashlib
from sys
from os
from fnmatch

CHUNK_SIZE=8192
def find_specific_files(root,patterns=['*'],exclude_dirs=[]):
pass
def get_chunk(filename):
with open(filename) as f:
while True:
chunk=f.read(CHUNK_SIZE)
if not chunk:
break
else:
yield chunk
def get_file_checksum(filename):
h=hashlib.md5()
for chunk in get_chunk(filename):
h.update(chunk)
return h.hexdigest()
def main():
sys.argv.append("")
directory=sys.argv[1]
if not os.path.isdir(directory)
raise SystemExit("{0} is not a directory".format(directory))
record={}
for item in find_specific_files(directory):
checksum=get_file_checksum(item)
if checksum in record:
print('find {0} vs {1}'.format(record[checksum],item))
else:
record[checksum]=item
if name=='main':
main()

上一篇:Spark 源码分析 -- BlockStore


下一篇:拒绝从入门到放弃_《Python 核心编程 (第二版)》必读目录