singlefile.py
来源:互联网 发布:godaddy新加坡注册域名 编辑:程序博客网 时间:2024/06/05 07:15
#! encoding=utf-8import osimport os.pathAllFiles = {}MinSize = 8100def 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 # 创建一个loggerlogger = 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添加handlerlogger.addHandler(fh)logger.addHandler(ch) # 记录一条日志#logger.info('foorbar')#该代码片段来自于: http://www.sharejs.com/codes/python/6248import pythoncomfrom win32com.shell import shellfrom win32com.shell import shellcondef 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 filecmpdef 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 DirListDirList.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] )
0 0
- singlefile.py
- py
- py
- py
- py
- py
- py
- py
- Py
- bin2hex.py && hex2bin.py
- web.py (url.py)
- [py]py存放家具
- Xctf之调皮的py-py-py
- dir_size.py
- sendEmail.py
- Html.py
- web.py
- mail.py
- mesos集群部署教程
- gtk+程序在关闭主窗口时的事件流
- toString的推荐写法
- 三个因素决定你的薪水高低
- 开源中国源码学习(四)——主界面总体认识
- singlefile.py
- 【Leetcode】Edit Distance #72
- FSMC STM32 + FPGA
- 开源中国源码学习(五)——切换皮肤(日间模式和夜间模式)
- 【LeetCode-面试算法经典-Java实现】【107-Binary Tree Level Order Traversal II(二叉树层序遍历II)】
- 【LeetCode-面试算法经典-Java实现】【108-Convert Sorted Array to Binary Search Tree(排序数组转变为平衡二叉树)】
- 【LeetCode-面试算法经典-Java实现】【109-Convert Sorted List to Binary Search Tree(排序链表转换成二叉排序树)】
- hdoj1176免费馅饼【dp】
- 网桥和网桥相连的网络