脚本中使用的md5sum工具下载地址如下:
#!/usr/bin/python#coding=utf-8import osimport shutil#获取某个文件的md5值def getmd5(dir): cmd = 'C:\\Users\\Administrator\\Desktop\\md5sum.exe' + ' ' + dir md5sum = os.popen(cmd) content = md5sum.readlines() content_split = content[3].split() realmd5 = content_split[0] return realmd5#获取需要拷贝的源文件的md5值srcfile = 'C:\\Users\\Administrator\\Desktop\\testdir\\ccc.txt'initialmd5 = getmd5(srcfile)#print initialmd5if __name__ == '__main__': #输入需要拷贝的次数 count = input('please input how many counts do you want to test:') #开始执行拷贝 for i in range(count): dstfile = 'C:\\Users\\Administrator\\Desktop\\testdir\\test%d.txt' %(i + 1) #拷贝数据 shutil.copyfile(srcfile,dstfile) #校验新拷贝数据的md5值,与源文件md5对比,验证数据一致性 checkmd5 = getmd5(dstfile) if checkmd5 == initialmd5 : print 'This is the %d copy' %(i + 1) print checkmd5 continue else: print 'This is the %d copy' %(i + 1) print 'data inconsistency'