python小工具:检索目录大小
2016-04-09 13:21
471 查看
#!/usr/bin/python
#Filename: filesize.py
import sys,os,re,time
print sys.argv[1]
mypath = sys.argv[1]
curlist = os.listdir(mypath)
print_list = {}
#print curlist
time.clock()
for curfile in curlist:
#print curfile
if re.search("data",curfile):
#print('test')
continue
fullpath = os.path.join(mypath,curfile)
#print fullpath
size = 0.0
if os.path.isdir(fullpath):
for root, dirs, files in os.walk(fullpath):
for fn in files:
if os.path.isfile(os.path.join(root,fn)):
size += os.path.getsize(os.path.join(root,fn))
elif os.path.isfile(fullpath):
size = os.path.getsize(fullpath)
print('%-50.50s %d MB' % (fullpath,int(size/1024/1024)))
print_list[fullpath] = size
sort=sorted(print_list.items(),key=lambda e:e[1],reverse=True)
for item in sort:
print('%-50.50s %d MB' % (item[0],int(item[1]/1024/1024)))
print time.clock(),'secs'
#Filename: filesize.py
import sys,os,re,time
print sys.argv[1]
mypath = sys.argv[1]
curlist = os.listdir(mypath)
print_list = {}
#print curlist
time.clock()
for curfile in curlist:
#print curfile
if re.search("data",curfile):
#print('test')
continue
fullpath = os.path.join(mypath,curfile)
#print fullpath
size = 0.0
if os.path.isdir(fullpath):
for root, dirs, files in os.walk(fullpath):
for fn in files:
if os.path.isfile(os.path.join(root,fn)):
size += os.path.getsize(os.path.join(root,fn))
elif os.path.isfile(fullpath):
size = os.path.getsize(fullpath)
print('%-50.50s %d MB' % (fullpath,int(size/1024/1024)))
print_list[fullpath] = size
sort=sorted(print_list.items(),key=lambda e:e[1],reverse=True)
for item in sort:
print('%-50.50s %d MB' % (item[0],int(item[1]/1024/1024)))
print time.clock(),'secs'
相关文章推荐
- python升级步骤
- filter 、map 、reduse、sorted 作用、特性及实例
- ubuntu14.04安裝numpy,scipy
- 关于unicode的学习
- sorted 函数
- 一个简单的Python爬虫
- python 装饰器
- python之路2
- python 安装numpy,scipy,matplotlib算法库
- python学习笔记(excel+requests)
- python tornado微信开发
- python 学习笔记3(循环方式;list初始化;循环对象/生成器/表推导;函数对象;异常处理)
- Python 练习实例2
- python 分页
- Python之路【第十八篇】Django小项目webQQ实现
- python中if __name__ == '__main__': 的解析
- Counting Bobs!
- python安装paramiko模块
- 在MacOS下Python安装lxml报错xmlversion.h not found 报错的解决方案
- python4.3笔记汇总(图片上不去啊)