Posted on 2009-07-28 14:07
Hero 阅读(441)
评论(0) 编辑 收藏 引用 所属分类:
资料整理
1 #!/usr/bin/env python
2 #
3 # getDirSize2.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
23 import os
24 #from os import listdir
25
26 def getDirSize( source ) :
27 size = 0L
28 if os.path.isfile( source ) :
29 size += os.stat( source )[6]
30 elif os.path.isdir( source ) :
31 for src in os.listdir( source ) :
32 srcpath = os.path.join( source, src )
33 print srcpath
34 size += getDirSize( srcpath )
35
36 return size
37
38 def main():
39
40 dirname = r"/home/wangzr"
41 print getDirSize( dirname ) / 1024 /1024
42 return 0
43
44 if __name__ == '__main__': main()
45