__author__ = 'bruce'

import os
from os.path import join,getsize

def getdirsize(dir):
    size=0l
    for (root,dirs,files) in os.walk(dir):
        
        for name in files:
            try:
                #print getsize(join(root,name))
                size += getsize(join(root,name))
            except:
                continue

        #直接用下面这句代码,在ubuntu 会出错,在windows 下没测试过。
        #size += sum([getsize(join(root,name)) for name in files])
    return size

if __name__ == '__main__':
    filesize = getdirsize(r'/home/candy/')
    print 'There are %.2f ' %(filesize/1024),'Kb in /home/bruce/Downloads'

  

相关文章:

  • 2021-05-25
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-01
  • 2021-07-09
  • 2022-12-23
  • 2021-06-19
  • 2021-11-07
  • 2021-08-15
相关资源
相似解决方案