defmain(): withopen('文件信息.txt', encoding='utf-8-sig', mode='r') as inF: for line in inF: temp = line.strip().split('#')[0].split('\t\t') print(temp) _md5 = temp[0] flag = 0 for parent, dirnames, filenames in os.walk('.\\',topdown=False): for filename in filenames: file_path = os.path.join(parent, filename) withopen(file_path, 'rb') as fileF: md5obj = hashlib.md5() md5obj.update(fileF.read()) _hash = md5obj.hexdigest().upper() if _md5 == _hash: flag = 1 break if flag: break dirFile = temp[2].strip().split('_') pathTemp = 'c:\\' for i in dirFile: pathTemp += i+'\\' os.mkdir(pathTemp) shutil.copy(file_path, pathTemp)