我希望你是我独家记忆

一段永远封存的记忆,随风而去
posts - 263, comments - 31, trackbacks - 0, articles - 3
   :: 首页 :: 新随笔 ::  :: 聚合  :: 管理

python获取文件夹大小(1)

Posted on 2009-07-28 14:07 Hero 阅读(2586) 评论(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 


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理