判断两个不同目录下文件是否相同,并输出改变或变更文件的路径至
发布时间:2020-12-17 17:24:03 所属栏目:Python 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 import osimport filecmpimport datetimefilepath1 = {}filepath2 = {}start_time = datetime.datetime.now()def get_file_path_list(path): file_pat
|
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 import os
import filecmp
import datetime
filepath1 = {}
filepath2 = {}
start_time = datetime.datetime.now()
def get_file_path_list(path):
file_path = {}
for root,dir_list,file_list in os.walk(path):
for file_name in file_list:
file_path[(root + '' + file_name)] = 1
return file_path
def get_counter_of_file_path_list(filepathlist):
count = 0
for fp in filepathlist:
if fp != None:
count += 1
return count
def write_to_txt(filepathinfo):
if filepathinfo != None:
f = open('file_contrast.txt','a')
f.writelines(filepathinfo + 'n')
f.close()
def get_change_and_less_files_path(beforefilepath,afterfilepath,count):
for fp1 in beforefilepath:
temp = 0
for fp2 in afterfilepath:
if fp1[3:] == fp2[3:]:
if filecmp.cmp(fp1,fp2):
continue
else:
print 'change file:' + fp1
write_to_txt('change file:' + fp1)
else:
temp += 1
if temp == count:
print 'less file:' + fp1
write_to_txt('less file:' + fp1)
def get_more_files_path(beforefilepath,count):
for fp2 in afterfilepath:
temp = 0
for fp1 in beforefilepath:
if fp1[3:] == fp2[3:]:
if filecmp.cmp(fp1,fp2):
continue
else:
temp += 1
if temp == count:
print 'more file:' + fp2
write_to_txt('more file:' + fp2)
path1 = r'E:testFre_Data_beforeScale_subframe0_New'
path2 = r'F:testFre_Data_beforeScale_subframe0_New'
filepath1 = get_file_path_list(path1)
filepath2 = get_file_path_list(path2)
count1 = get_counter_of_file_path_list(filepath1)
count2 = get_counter_of_file_path_list(filepath2)
get_change_and_less_files_path(filepath1,filepath2,count2)
get_more_files_path(filepath1,count1)
end_time = datetime.datetime.now()
print r'统计时间: %s 秒' % (end_time - start_time).seconds
print 'Done!'
以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
