python 文件夹比较
参考:http://blog.csdn.net/imzoer/article/details/8675078
文件比较:filecmp模块:filecmp
'''
Created on 2014-6-6
@author: jyp
@module: pro1.filecmp_test}
'''
import time
import os
from site import setBEGINLIBPATH
def getPrettyTime(state):
return time.strftime('%y-%m-%d %H:%M:%S', time.localtime(state.st_mtime))
def compareDir(A_path, B_path):
A_files = []
B_files = []
for root, dirs, files in os.walk(A_path):
for file in files:
A_files.append(root + "\\" + file)
for root, dirs, files in os.walk(B_path):
for file in files:
B_files.append(root + "\\" + file)
a_files = []
b_files = []
a_path_len = len(A_path)
b_path_len = len(B_path)
for file in A_files:
a_files.append(file[a_path_len:])
for file in B_files:
b_files.append(file[b_path_len:])
setA = set(a_files)
setB = set(b_files)
commonfiles = setA & setB
print "#================================="
print "common in '", A_path, "' and '", B_path, "'"
print "#================================="
print '\t\t\ta:\t\t\t\t\t\tb:'
for f in sorted(commonfiles):
print f + "\t\t" + getPrettyTime(os.stat(A_path + "\\" + f)) + "\t\t" + getPrettyTime(os.stat(B_path + "\\" + f))
onlyA = setA - setB
print "#================================="
print "only in A '", A_path
print "#================================="
print '\t\t\ta:\t\t\t\t\t\tb:'
for f in sorted(onlyA):
print f + "\t\t" + getPrettyTime(os.stat(A_path + "\\" + f))
onlyB = setB - setA
print "#================================="
print "only in B'" , B_path
print "#================================="
print '\t\t\ta:\t\t\t\t\t\tb:'
for f in sorted(onlyB):
print f + "\t\t" + getPrettyTime(os.stat(B_path + "\\" + f))
if __name__ == '__main__':
compareDir('f:/srcDir', 'f:/destDir')
python 文件夹比较的更多相关文章
- Python文件夹备份
Python文件夹备份 import os,shutil def file_copy(path1,path2): f2 = [filename1 for filename1 in os.listdir ...
- Python 文件夹及文件操作
import os import os.path from shutil import copy def copyfile(src, dst): count = 1 for filename in o ...
- python文件夹遍历,文件操作,获取文件修改创建时间
在Python中,文件操作主要来自os模块,主要方法如下: os.listdir(dirname):列出dirname下的目录和文件os.getcwd():获得当前工作目录os.curdir:返回当前 ...
- python文件夹中pycache文件是什么
python(pycache文件的问题):python属于脚本语言,执行python文件需要通过python解释器将源码转换为字节码,然后供cpu读取,pycache文件夹里面保存的就是py文件对应的 ...
- python 文件夹扫描
扫描指定文件夹下的文件.或者匹配指定后缀和前缀的函数. 假设要扫描指定文件夹下的文件,包含子文件夹,调用scan_files("/export/home/test/") 假设要扫描 ...
- python文件夹copy器(多进程版)
本节的练习的要求如下: 输入要拷贝文件夹的文件名称 读取该文件夹下的所有文件 启动5个进程来拷贝文件夹,将拷贝成功的文件名称放入队列中 主进程中显示文件拷贝的进度 代码如下: import multi ...
- Python文件夹与文件的操作(转)
最近在写的程序频繁地与文件操作打交道,这块比较弱,还好在百度上找到一篇不错的文章,这是原文传送门,我对原文稍做了些改动. 有关文件夹与文件的查找,删除等功能 在 os 模块中实现.使用时需先导入这个模 ...
- python文件夹批处理操作
如图所示,有一个test文件夹,里面有3个子文件夹,每个子文件夹中有若干图片文件 #场景1 读取一个文件夹中所有文件,存入到一个list表中 #coding:utf-8 from __futur ...
- Python文件夹与文件的操作 ZZ
最近在写的程序频繁地与文件操作打交道,这块比较弱,还好在百度上找到一篇不错的文章,这是原文传送门,我对原文稍做了些改动. 有关文件夹与文件的查找,删除等功能 在 os 模块中实现.使用时需先导入这个模 ...
- python文件夹操作
1.遍历文件夹下所有文件2.将后缀为.DCM的文件复制到指定文件夹 import os import shutil def all_path(dirname): result = []#所有的文件 f ...
随机推荐
- CSS实现限制字数功能
<div style="width:200px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis; border:1 ...
- Array数组方法的总结
添加元素: 1. push(arg1,arg2,arg3....) 向数组的尾部添加元素,返回值是数组的长度. 2.unshift(arg1,arg2,arg3....) 向数组的头部添加元素,返回 ...
- UVA 12166 Equilibrium Mobile
题意: 给出数个天平,每个天平的结构都类似于二叉树,只有左右重量都相等时才平衡,求每个天平最少改多少个秤砣,也就是叶子结点可以使得整个天平平衡.天平的深度不超过16. 分析: 要使得改动的数量最少,那 ...
- 利用DreamweaverCS5制作一个含有动态标题的教程
DreamweaverCS5怎么制作一个含有动态标题?做一个网页就先要做一个标题,一个好标题会让网页让人印象深刻,有动态的标题会让网页更生动,下面我就介绍一下怎么制作一个含有动态的标题 做一个网页 ...
- 常用WebService收集
尊重原著作:本文转载自http://www.cnblogs.com/tianguook/archive/2010/09/29/1838469.html 天气预报Web服务,数据来源于中国气象局Endp ...
- panel控件 换行
Panel1.Controls.Add(new LiteralControl("<BR/>"));
- SQL SERVER 数据类型详解(SQL Server 2008)
数据类型类别 SQL Server 中的数据类型归纳为下列类别: 数字类型 1.精确数字 2.近似数字 3.日期和时间 字符串类型 4.非Unicode字符串 4.Unicode字符串 5.二进制字符 ...
- spring中的定时任务调度用例
在application-quartz.xml配置文件中添加如下配置信息: <!-- Quartz --> <bean id="getSendEmailObject ...
- 一个简单的shell脚本
一个简单的shell脚本 一个简单的shell脚本 编写 假设我想知道目前系统上有多少人登录,使用who命令可以告诉你现在系统有谁登录: 1.[KANO@kelvin ~]$ who2.KANO tt ...
- xml drawable
1.Shape drawable:改变组件的形状和渐变xml shape标签 corner标签:改变轮廓 gradient:颜色填充的渐变 android:angle android:angle=“ ...