1. [root@localhost python]# cat dircmptest.py
  2. #!/usr/bin/python
  3. import filecmp
  4. path1="/root/python/a"
  5. path2="/root/python/b"
  6. test=filecmp.dircmp(path1,path2) #比较目录,path1是左,path2是右
  7. #test.report() #比较当前目录中指定的内容
  8. #test.report_partial_closure() #比较当前目录及第一级子目录内容
  9. #test.report_full_closure() #递归比较目录内的所有内容
  10. print 'all files and dirs in left_list(path1): '+str(test.left_list) #显示左列表内容
  11. print "common files"+str(test.common_files) #显示两个目录共同的文件(文件名相同)
  12. print "diff files"+str(test.diff_files) #显示两个目录内文件名相同但是内容不同的文件
  13. print "common dirs"+str(test.common_dirs) #显示两个目录内子目录相同的目录名
  14. print "common dirs and files"+str(test.common) #显示两个目录名称相同的文件或者目录
  15. print "only in left list,no in right list: "+str(test.left_only) #显示只有左目录特有的文件
  16. print "same_files is: "+str(test.same_files) #显示两个目录内文件名相同且内容相同的文件
  17. [root@localhost python]# ./dircmptest.py
  18. all files and dirs in left_list(path1): ['a.txt', 'b.txt', 'info.py', 'k', 'k.py', 'kali', 'linux']
  19. common files['kali', 'a.txt', 'info.py']
  20. diff files['a.txt']
  21. common dirs['k']
  22. common dirs and files['kali', 'a.txt', 'info.py', 'k']
  23. only in left list,no in right list: ['b.txt', 'k.py', 'linux']
  24. same_files is: ['kali', 'info.py']
  25. [root@localhost python]# ls a a/k b b/k
  26. a:
  27. a.txt b.txt info.py k kali k.py linux
  28. a/k:
  29. c.txt
  30. b:
  31. a.txt bp c.txt info.py k kali
  32. b/k:
  33. k.py linux
  34. [root@localhost python]# cat a/a.txt b/a.txt
  35. linux
  36. ok
  37. [root@localhost python]# cat a/kali b/kali
  38. a
  39. a
  40. [root@localhost python]#

python简单实现目录对比的更多相关文章

  1. Python学习小目录汇总

    python其他知识目录 python基础知识-1 1.typora软件使用 2.python解释器安装 3.Python解释器环境变量添加 4.计算机编码知识: 5.输出print(): 6.变量 ...

  2. python高级学习目录

    1. Linux介绍.命令1.1. 操作系统(科普章节) 1.2. 操作系统的发展史(科普章节) 1.3. 文件和目录 1.4. Ubuntu 图形界面入门 1.5. Linux 命令的基本使用 1. ...

  3. Python简单实现在线更新下载

    Python简单实现 软件在线更新 在线下载(Python simple implementation of software online update and download) 文章来自:htt ...

  4. 老猿Python博文汇总目录--按标题排序

    ☞ ░ 前往老猿Python博文目录 ░ 本部分为老猿CSDN全部博文的汇总(含转载部分),所有文章在此未进行归类,仅按文章标题排序,方便关键字查找.本部分内容将至少以周为单位定期更新,可能不包含发布 ...

  5. Python简单爬虫入门三

    我们继续研究BeautifulSoup分类打印输出 Python简单爬虫入门一 Python简单爬虫入门二 前两部主要讲述我们如何用BeautifulSoup怎去抓取网页信息以及获取相应的图片标题等信 ...

  6. Selenium + PhantomJS + python 简单实现爬虫的功能

    Selenium 一.简介 selenium是一个用于Web应用自动化程序测试的工具,测试直接运行在浏览器中,就像真正的用户在操作一样 selenium2支持通过驱动真实浏览器(FirfoxDrive ...

  7. python 简单图像识别--验证码

    python  简单图像识别--验证码 记录下,准备工作安装过程很是麻烦. 首先库:pytesseract,image,tesseract,PIL windows安装PIL,直接exe进行安装更方便( ...

  8. Python 简单入门指北(二)

    Python 简单入门指北(二) 2 函数 2.1 函数是一等公民 一等公民指的是 Python 的函数能够动态创建,能赋值给别的变量,能作为参传给函数,也能作为函数的返回值.总而言之,函数和普通变量 ...

  9. python递归列出目录及其子目录下所有文件

    python递归列出目录及其子目录下所有文件 一.前言 函数的递归,简单来说,就是函数内部调用自己 先举个小例子,求阶乘 def factorial(n): if n == 0: return 1 e ...

随机推荐

  1. 房间安排 (nyoj 168)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...

  2. net core 获取网站目录

    AppContext.BaseDirectory 获取项目的根目录

  3. 7.6 C++基本序列式容器效率比较

    参考:http://www.weixueyuan.net/view/6403.html 总结: 对于vector而言,它只是一个可以伸缩长度的数组 对于deque而言,它是一个可以操作头部和尾部的并且 ...

  4. 5.8 C++重载自增与自减操作符

    参考:http://www.weixueyuan.net/view/6386.html 注意: 自增“++”与自减“--”都是一元操作符,其前置和后置两种形式都可以被重载. 前置 stopwatch ...

  5. L245

    The State Council will lay down new rules that aim to make management compatible with internationall ...

  6. Python 基础day3

    1.简述bit,byte,kb,MB,GB,TB的关系 1TB=1024GB;   1GB=1024MB ;  1MB=1024kb: 1kb=1024byte ; 1byte=8bit 2.简述as ...

  7. Flask源码阅读-第三篇(flask\_compat.py)

    源码 # -*- coding: utf-8 -*-""" flask._compat ~~~~~~~~~~~~~ Some py2/py3 compatibility ...

  8. php优秀框架codeigniter学习系列——common.php

    文件位于system/core/common.php,是框架核心文件. 该文件中定义了一系列的函数,都是框架运行中经常需要用到的.下面逐一介绍. is_php /** * Determines if ...

  9. ob_get_contents 获取输出缓存内容

    function _require($filename){ ob_start(); include $filename; $content = ob_get_contents(); ob_end_cl ...

  10. SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)

    1.pom.xml增加依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...