1import hashlib 2import os 3import sys 4 5def main(): 6 filenames, hashes, sizes = [], [], [] 7 8 for file in sys.argv[1:]: 9 if not os.path.isfile(file): 10 continue 11 12 with open(file, 'rb') as f: 13 data = f.read() 14 md5 = hashlib.md5() 15 md5.update(data) 16 filenames.append(os.path.split(file)[1]) 17 hashes.append(md5.hexdigest()) 18 sizes.append(str(len(data))) 19 20 print('{:40s} {:<32s} {:<9s}'.format('File', 'MD5', 'Size')) 21 for f, h, s in zip(filenames, hashes, sizes): 22 print('{:40s} {:>32s} {:>9s}'.format(f, h, s)) 23 24 25 26if __name__ == "__main__": 27 sys.exit(int(main() or 0)) 28