例子,使用python中os模块获取文件夹大小。
代码:
#!/usr/bin/python
# www.jb200.com
import os
def get_size(src):
'''Get the size of a directory or a file'''
size=0L
if os.path.isfile(src):
size=os.stat(src)[6]
elif os.path.isdir(src):
for item in os.listdir(src):
itemsrc=os.path.join(src,item)
print item
#iterate to caculate the directory size
size+=get_size(itemsrc)
return size
if __name__=='__main__':
dirname=r'c:work'
print get_size(dirname)