[Python] 获取文件夹大小的python代码 →→→→→进入此内容的聊天室

来自 , 2021-01-13, 写在 Python, 查看 114 次.
URL http://www.code666.cn/view/6651526b
  1. import os
  2. from os.path import join, getsize
  3.  
  4. def getdirsize(dir):
  5.    size = 0L
  6.    for root, dirs, files in os.walk(dir):
  7.       size += sum([getsize(join(root, name)) for name in files])
  8.    return size
  9.  
  10. if __name__ == '__main__':
  11.    filesize = getdirsize(r'c:\windows')
  12.    print 'There are %.3f' % (size/1024/1024), 'Mbytes in c:\\windows'
  13. #//python/1159

回复 "获取文件夹大小的python代码"

这儿你可以回复上面这条便签

captcha