#----------------------------------------------------------------
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#----------------------------------------------------------------
# author : pcfeng502
#
# e-mail : pcfeng502@126.com
#
# file : foldersizelist_v02.py
#
# introduction:
# 统计一个文件夹下的子文件夹的大小
# 方便删除文件夹中的子文件夹
#----------------------------------------------------------------
# works with python 3.3.2; windows 7 64bit
import os
from os.path import join
from os.path import getsize
exceptioncount = 0;
def getdirsize(dir):
size = 0;
if os.path.isdir(dir):
for root, dirs, files in os.walk(dir):
try:
size = sum(getsize(join(root, name)) for name in files)
except filenotfounderror:
global exceptioncount
exceptioncount =1
return size;
else:
size = getsize(dir)
return size
def getsubdir(dir):
subdirlist = os.listdir(dir)
return subdirlist
#todo
##def getpath():
if __name__ == '__main__':
#todo read the file name input
path = input('input the path you want to check out size\n');
rootpath = path;
print(rootpath);
subdir = getsubdir(rootpath);
wholedirsize = 0;
subdirsize = [];
print('there are', len(subdir), 'files folders in', rootpath);
for i in range(len(subdir)):
subdirsize.append(getdirsize(join(rootpath, subdir[i])));
wholedirsize = subdirsize[i];
print('there are %.3f'%(subdirsize[i]/1024/1024), 'mbytes in', subdir[i]);
print('there are %.3f' %(wholedirsize/1024/1024), 'mbytes in', rootpath);
print('there are %d' %(exceptioncount), 'errors in counting');
用户登录
还没有账号?立即注册
用户注册
投稿取消
| 文章分类: |
|
还能输入300字
上传中....
我可是巴拉巴拉小魔仙呢