Posted on 2009-07-28 14:07
Hero 阅读(2612)
评论(0) 编辑 收藏 引用 所属分类:
资料整理
1 #!/usr/bin/env python
2 #
3 # getDirSize.py
4 #
5 # Copyright 2009 Hiro <wangzhaoren@gmail.com>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21
22 import os
23 from os.path import join, getsize
24
25 def getDirSize( dir ):
26 size = 0L
27 for root, dirs, files in os.walk(dir):
28 size += sum( [getsize(join(root, name)) for name in files] )
29 return size
30
31 def main():
32
33 filesize = getDirSize( "/home/wangzr" )
34 print ( "there are %0.3f" %(filesize/1024/1024), "Mb in /home/wangzr" )
35
36 return 0
37
38 if __name__ == '__main__': main()
39