分享Python获取文件及文件夹大小的方法源码,python源码,用Python编程语言代


用Python编程语言代码编写了一个小程序,可以快速计算获取文件及文件夹大小。想通过python知道文件或文件夹占用空间大小的方法,在编橙之家把这个如何通过python获取目录文件大小的程序源码分享出来和大家一同学习进步。也可以通过这个python代码去改进,获取更多想要知道的信息。

Python os模块的使用方法介绍

import osfrom 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#www.iplaypy.comif '__name__' == '__main__':   filesize = getdirsize(r'c:\windows')     print 'There are %.3f' % (size/1024/1024), 'Mbytes in c:\\windows'

Python文件及文件夹操作相关文章推荐:
1、Python遍历文件夹目录与文件操作
2、Python 文件对象常用内建方法
3、Python合并多个文件为一个文本文件的方法源码
4、Python open()函数文件打开、读、写write操作详解

编橙之家文章,

评论关闭