判断两个不同目录下文件是否相同,并输出改变或变更文件的路径至txt,变更txt,import osimp
文章由Byrx.net分享于2019-03-23 04:03:04
判断两个不同目录下文件是否相同,并输出改变或变更文件的路径至txt,变更txt,import osimp
import osimport filecmpimport datetimefilepath1 = {}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_pathdef get_counter_of_file_path_list(filepathlist): count = 0 for fp in filepathlist: if fp != None: count += 1 return countdef 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).secondsprint 'Done!'
相关内容
- 埃拉托塞尼筛法求素数,素数,from math im
- Python创建系统目录,python创建目录,import os
- 免翻墙上google(python3.3版)已打包,,#-*-coding:u
- 用pyinotify监控文件系统示例,pyinotify监控示例,Pyinotif
- 在目录下查找包含某字符串的文件的python代码,,一个
- python连接mongodb操作代码,pythonmongodb代码,__author__ =
- 演示断言,,#演示断言#!/usr/
- 专家级程序员写阶乘,专家程序员阶乘,#专家级程序员
- QQ空间点赞机,QQ空间赞机,print 'hello
- #python3 练手 #格式化当天日期,,#python3 练手#
评论关闭