清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #---------------------------------------------------------------- # -*- coding: utf-8 -*- #!/usr/bin/env python #---------------------------------------------------------------- # Author : pcfeng502 # # E-Mail : pcfeng502@126.com # # File : folderSizeList_v02.py # # Introduction: # 统计一个文件夹下的子文件夹的大小 # 方便删除文件夹中的子文件夹 #---------------------------------------------------------------- # works with Python 3.3.2; windows 7 64bit import os from os.path import join from os.path import getsize exceptionCount = 0 ; def getDirSize(dir): size = 0 ; if os.path.isdir(dir): for root, dirs, files in os.walk(dir): try : size + = sum(getsize(join(root, name)) for name in files) except FileNotFoundError: global exceptionCount exceptionCount + = 1 return size; else : size = getsize(dir) return size def getSubDir(dir): subDirList = os.listdir(dir) return subDirList #todo ##def getpath(): if __name__ = = '__main__' : #TODO read the file name input path = input( 'Input the path you want to check out size\n' ); rootpath = path; print (rootpath); subdir = getSubDir(rootpath); wholeDirSize = 0 ; subDirSize = []; print ( 'There are' , len(subdir), 'files+folders in' , rootpath); for i in range(len(subdir)): subDirSize.append(getDirSize(join(rootpath, subdir[i]))); wholeDirSize + = subDirSize[i]; print ( 'There are %.3f' % (subDirSize[i] / 1024 / 1024 ), 'Mbytes in' , subdir[i]); print ( 'There are %.3f' % (wholeDirSize / 1024 / 1024 ), 'Mbytes in' , rootpath); print ( 'There are %d' % (exceptionCount), 'errors in counting' ); |