判断两个不同目录下文件是否相同,并输出改变或变更文件的路径至txt
- 作者: 从不袭击少女
- 来源: 51数据库
- 2022-08-12
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, afterfilepath, 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:\test\Fre_Data_beforeScale_subframe0_New'
path2 = r'F:\test\Fre_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, filepath2, count1)
end_time = datetime.datetime.now()
print r'统计时间: %s 秒' % (end_time - start_time).seconds
print 'Done!'
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
