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'c:/windows') 
   print 'There are %.3f' % (size/1024/1024), 'Mbytes in c://windows'

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8475.html

(0)
上一篇 2021年7月18日 19:44
下一篇 2021年7月18日 19:44

相关推荐

发表回复

登录后才能评论