• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python实现比较两个文件夹中代码变化的方法

Python实现比较两个文件夹中代码变化的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python 创建文件夹,python 遍历文件夹,python 删除文件夹,python读取文件夹,python 文件夹等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python实现比较两个文件夹中代码变化的方法。分享给大家供大家参考。具体如下:

这里将修改代码后的目录与原始目录做对比,罗列出新增的代码文件,以及修改过的代码文件

# -*- coding: utf-8 -*-
import os;
folderA = "F:\\Projects\\FreeImageV3_14_1\\".lower();
folderB = u"E:\\Software\\图像解码库\\FreeImage3141\\FreeImage\\".lower();
filePathsA = {};
filePathsB = {};
for root,dirs,files in os.walk(folderA):
  for fileName in files:
    filePathsA[(root + "\\" + fileName).lower()] = 1;
for root,dirs,files in os.walk(folderB):
  for fileName in files:
    filePathsB[(root + "\\" + fileName).lower()] = 1;
# 在filePathsA中,找到所有和filePathsB中不一致的文件的路径    
modifiedFilePath = [];
addedFilePath = [];
for filePathA in filePathsA:
  folderALen = len(folderA);
  filePathB = folderB + filePathA[folderALen:]; 
  idx = filePathA.rfind(".");
  if idx == -1:
    continue;
  ext = filePathA[idx + 1:];
  ext = ext.lower();
  if ext != "c" and ext != "h" and ext != "cpp" and ext != "cxx":
    continue;
  if filePathB not in filePathsB:
    addedFilePath.append(filePathA);
    continue;
  text_file = open(filePathA, "r");
  textA = text_file.read();
  text_file.close();
  text_file = open(filePathB, "r");
  textB = text_file.read();
  text_file.close();
  if textA != textB:   
    modifiedFilePath.append(filePathA);
output = open('res.txt', 'w');
output.write("added files:\n");
for filePath in addedFilePath:
  output.write(filePath + "\n");
output.write("modified files:\n");
for filePath in modifiedFilePath:
  output.write(filePath + "\n");
output.close();

</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python遍历文件夹和读写文件的实现方法
  • Python实现Windows和Linux之间互相传输文件(文件夹)的方法
  • python 实现删除文件或文件夹实例详解
  • Python文件与文件夹常见基本操作总结
  • python之文件的读写和文件目录以及文件夹的操作实现代码
  • Python遍历文件夹和读写文件的实现代码
  • 动感网页相册 python编写简单文件夹内图片浏览工具
  • python之文件的读写和文件目录以及文件夹的操作实现代码
  • Python遍历文件夹和读写文件的实现代码
  • 动感网页相册 python编写简单文件夹内图片浏览工具

相关文章

  • python实现文件名批量替换和内容替换
  • Python中死锁的形成示例及死锁情况的防止
  • Python使用Socket(Https)Post登录百度的实现代码
  • 浅谈Python程序与C++程序的联合使用
  • python采集博客中上传的QQ截图文件
  • python将文本转换成图片输出的方法
  • Python 文件和输入输出小结
  • python获取list下标及其值的简单方法
  • Python中使用Flask、MongoDB搭建简易图片服务器
  • python生成式的send()方法(详解)

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python每次处理固定个数的字符的方法总结
    • 下载给定网页上图片的方法
    • python中for语句简单遍历数据的方法
    • 浅析Python中yield关键词的作用与用法
    • 初学Python实用技巧两则
    • Python类的用法实例浅析
    • Python的SQLalchemy模块连接与操作MySQL的基础示例
    • python里大整数相乘相关技巧指南
    • 使用IPython来操作Docker容器的入门指引
    • Python实现基本线性数据结构

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有