标签:
import os, sys from stat import * BIG_FILE_THRESHOLD = 6000L #1000000L dict1 = {} # dict2 = {} # def treewalk(path): try: for i in os.listdir(path): mode = os.stat(path+"/"+i).st_mode if S_ISDIR(mode) <> True: filename = path+"/"+i filesize = os.stat(filename).st_size if filesize < BIG_FILE_THRESHOLD: if filesize in dict1: dict2[filename] = filesize dict2[dict1[filesize]]=filesize else: dict1[filesize] = filename else: treewalk(path+"/"+i) except WindowsError: pass def printdict(finaldict): for i_size in finaldict.values(): print i_size for j_name in finaldict.keys(): if finaldict[j_name] == i_size: print j_name os.remove(j_name) print "\n" if __name__=="__main__": treewalk(sys.argv[1]) printdict(dict2)
使用方法 remove c:/xx
标签:
原文地址:http://www.cnblogs.com/dongchi/p/4517923.html