您的位置:首页 > 编程语言 > Python开发

Python小应用:列出所有源文件及其大小

2006-04-20 10:05 337 查看
最近需要把项目中的所有源文件及其大小列出来,导入word文档。(共991个文件)

想了想,就用python实现吧,现学现用,下面是代码:

import os
dest = raw_input('dir:')
res = open('d:/res.txt', 'w')
red = []
for root, dirs, files in os.walk(dest):
for file in files:
if (file not in red) and (not file.startswith('moc_')) and (file.endswith('.cpp')/
or file.endswith('.h') or file.endswith('.h') or file.endswith('.ui')):
stats = os.stat(os.path.join(root, file))
res.write( '%-30s/t%d/n' %(file, stats[6]))
red.append(file)

真是简洁呀,用C++是难有此效率(开发效率)的,呵呵
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: