#! encoding=utf-8

import os
import os.path AllFiles = {}
MinSize = 8100 def OneDir( DirName ):
if DirName[len(DirName)-1] <> "\\":
DirName = DirName + "\\"
tmpFiles = os.listdir( DirName )
for OneFile in tmpFiles:
OneFilePath = DirName + OneFile
if os.path.isdir( DirName + OneFile ):
OneDir( DirName + OneFile + "\\")
else:
statinfo = os.stat( OneFilePath )
if AllFiles.has_key( statinfo.st_size ):
OneKey = AllFiles[ statinfo.st_size ]
OneKey.append( OneFilePath )
AllFiles[ statinfo.st_size ] = OneKey
else:
if statinfo.st_size > MinSize:
# print statinfo.st_size
FileSize = statinfo.st_size
AllFiles[ FileSize ] = [ OneFilePath ]
# print AllFiles
# print AllFiles.keys() import logging # 创建一个logger
logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG) # 创建一个handler,用于写入日志文件
fh = logging.FileHandler('test.log')
fh.setLevel(logging.DEBUG) # 再创建一个handler,用于输出到控制台
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) # 定义handler的输出格式
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter) # 给logger加入handler
logger.addHandler(fh)
logger.addHandler(ch) # 记录一条日志
#logger.info('foorbar')
#该代码片段来自于: http://www.sharejs.com/codes/python/6248
import pythoncom
from win32com.shell import shell
from win32com.shell import shellcon
def MakeShortcut( lnkname, filename ):
logger.info(lnkname +' is linked to '+filename)
os.remove( lnkname )
shortcut = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink, None,
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
shortcut.SetPath(filename)
# shortcut.SetIconLocation(iconname,0)#可有可无,没有就默认使用文件本身的图标
# if os.path.splitext(lnkname)[-1] != '.lnk':
lnkname += ".lnk"
shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(lnkname,0) import filecmp
def FileCompare( SameSizeFiles ):
CompareResult = [[]]*len(SameSizeFiles)
for i in range( 1, len(SameSizeFiles) ):
for j in range( i ):
if filecmp.cmp(SameSizeFiles[i],SameSizeFiles[j]):
if len( CompareResult[ j ] ) > 1:
CompareResult[ j ].append( i )
else:
CompareResult[ j ] = [ i, j ]
break
for i in range( len(SameSizeFiles)-1 ):
if len( CompareResult[ i ] ) > 1:
for j in range( len( CompareResult[ i ] )-1 ):
MakeShortcut( SameSizeFiles[ CompareResult[ i ][j]],
SameSizeFiles[ CompareResult[i][ len( CompareResult[ i ] )-1 ] ] ) ############## start #############
DirList = []
while cmp(input,"#")<>0:
input = raw_input("please input folder names, \"#\" to finish input:")
DirList.append(input)
# print DirList
DirList.pop() for Dir in DirList:
OneDir( Dir ) print AllFiles.keys()
for EachSize in AllFiles.keys():
if (len( AllFiles[EachSize] ) > 1) & ( EachSize > MinSize ):
FileCompare( AllFiles[EachSize] )

singlefile.py的更多相关文章

  1. python调用py中rar的路径问题。

    1.python调用py,在py中的os.getcwd()获取的不是py的路径,可以通过os.path.split(os.path.realpath(__file__))[0]来获取py的路径. 2. ...

  2. Python导入其他文件中的.py文件 即模块

    import sys sys.path.append("路径") import .py文件

  3. import renumber.py in pymol

    cp renumber.py /usr/local/lib/python2.7/dist-packages/pymol import renumber or run /path/to/renumber ...

  4. python gettitle.py

    #!/usr/bin/env python # coding=utf-8 import threading import requests import Queue import sys import ...

  5. 解决 odoo.py: error: option --addons-path: The addons-path 'local-addons/' does not seem to a be a valid Addons Directory!

    情况说明 odoo源文件路径-/odoo-dev/odoo/: 我的模块插件路径 ~/odoo-dev/local-addons/my-module 在my-module中创建了__init__.py ...

  6. caffe机器学习自带图片分类器classify.py实现输出预测结果的概率及caffe的web_demo例子运行实例

    caffe机器学习环境搭建及python接口编译参见我的上一篇博客:机器学习caffe环境搭建--redhat7.1和caffe的python接口编译 1.运行caffe图片分类器python接口 还 ...

  7. 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优

    libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...

  8. MySqlNDB使用自带的ndb_setup.py安装集群

    在用Mysql做集群时,使用Mysql的NDB版本更易于集群的扩展,稳定和数据的实时性. 我们可以使用Mysql自带的工具进行集群安装与管理:ndb_setup.py.位于Mysql的安装目录bin下 ...

  9. 将做好的py文件打包成模块,供别人安装调用

    现在要将写完的3个py文件,打包. 步骤: 1.新建一个文件夹setup(名字随便取),在setup文件夹下,再新建一个文件夹financeapi. 2.将上面4个py文件拷贝至financeapi文 ...

随机推荐

  1. zabbix---简介

    zabbix---简介 今天又听人说zabbix,好吧特地回来看了看,和其他的好像差别也不大,不过他可以让监控,绘图,web前端与一体, 当然也可以实现分布式部署,不错的. 列举一下其功能特点 网络设 ...

  2. (转)淘淘商城系列——使用solrj来测试索引库

    http://blog.csdn.net/yerenyuan_pku/article/details/72892280 我们使用solrj来操作索引库,一般习惯先建一个单元测试类测试下增删改查方法是否 ...

  3. C# 创建与读写配置文件

    配置文件内容为 <?xml version="1.0" encoding="utf-8" ?> <configuration> < ...

  4. 校内测之zay与银临 (day2)(只有T1)

    一些与题目无关的碎碎念 推出式子来一定要化简!!!freopen不要写错!!!特判不要瞎搞!!!! 做到以上三点能高35分qwq T1 江城唱晚 你看数据那么大,显然又是一道数学题. 这里有n个种海棠 ...

  5. 如何做到在webpack打包vue项目后,在外部动态修改配置文件

    在我们做完vue项目后,只需要执行 npm run dist 就可以轻松进行打包转测试,可是如果我们临时需要修改一些配置文件比如域名,这时候我们就有点懵逼了,那就修改了再重新打一次包? NO NO N ...

  6. xmpp登录(2)

    XMPP中常用对象们: XMPPStream:xmpp基础服务类 XMPPRoster:好友列表类 XMPPRosterCoreDataStorage:好友列表(用户账号)在core data中的操作 ...

  7. background 背景类八大属性

    background 背景类八大属性 背景颜色(当同时定义了背景颜色和背景图像时,背景图像覆盖在背景颜色之上) background-image:背景图像 background-repeat:背景图像 ...

  8. Makefile,Shell command,Shell Language 之间的联系

    1. Makefile 首先要知道Makefile 是什么东西,Makefile 是一个指令文件,里面存储着自定义的命令(可以借助已有的命令创造而来)在不同的系统下对Makefile 的区别不一样,L ...

  9. Game Rank(NCPC 2016 大模拟)

    题目: The gaming company Sandstorm is developing an online two player game. You have been asked to imp ...

  10. 3.5.6 关系和boolean运算符

        Java包含丰富的关系运算符.要检测相等性,可以使用两个等号 == .例如, 3 == 7  的值为 false.       另外可以使用 != 检测不相等.例如,  3  ! = 7 的值 ...