给定一个包含几千个文件的目录,请输出所有 目录中完全相同的文件
我可以编写脚本从dir读取文件,但是我需要比较目录中每个文件的内容,并且输出应该像matches{f1,f2}{f4,f6}
#!/usr/bin/env python
import sys
import glob
import errno
path = '/home/harish/myfiles'
files = glob.glob(path)
for name in files: # 'file' is a builtin type, 'name' is a less-ambiguous variable name.
try:
with open(name) as f: # No need to specify 'r': this is the default.
sys.stdout.write(f.read())
except IOError as exc:
if exc.errno != errno.EISDIR: # Do not fail if a directory is found, just ignore it.
raise # Propagate other kinds of IOError.
您可以找到每个文件的md5和
像这样把它们放进字典里: {'md5':[“文件名1,文件名2”]}
那么
^{pr2}$相关问题 更多 >
编程相关推荐