python 获取文件夹大小

import os  
from os.path import join, getsize  
   
def getdirsize(dir):  
   size = 0L 
   for root, dirs, files in os.walk(dir):  
      size += sum([getsize(join(root, name)) for name in files])  
   return size  
   
if __name__ == '__main__':  
   filesize = getdirsize(r'/etc/')  
   print 'There are %.3f' % (size/1024/1024), 'Mbytes in /etc/'

  

posted on 2017-10-30 23:52  那个踩到香蕉皮的妖怪  阅读(199)  评论(0编辑  收藏  举报