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++是难有此效率(开发效率)的,呵呵
想了想,就用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++是难有此效率(开发效率)的,呵呵
相关文章推荐
- 列出文件夹下所有文件及其大小(递归的运用)
- python列出一个文件夹及其子目录的所有文件
- Python列出一个文件夹及其子目录的所有文件
- Python列出一个文件夹及其子目录的所有文件
- Android列出所有应用,点击可运行~
- VSTO在EXCEL里列出所有文件夹及其文件
- Python 语言及其应用 Chapter_6_Note 1 类的super功能
- Python 语言及其应用 Chapter_6_Note 2 用write()写文本文件
- python解释器实现及其嵌入式应用:一个四则运算计算器的实现
- 列出一个目录中所有文件及大小
- Python 语言及其应用 Chapter_4_Note_1 推导式
- java中File类的常用所有方法及其应用
- Python中SOAP项目的介绍及其在web开发中的应用
- python3爬虫之入门和正则表达式,获取IP地址, 隐马尔可夫模型及其在分词中的简单应用
- Python 中的 lambda 表达式及其简单应用
- python ( os , path , sys ) 找出指定目录下的所有文件,并求出大小且排序
- Python递归列出目录中文件脚本及其匿名函数
- python解释器实现及其嵌入式应用:认识Micro Python
- 续:C# 趣味小程序(4)——遍历特定目录及其子目录 (应用实例,压缩指定目录下的所有文件)
- 6.5-Python-语言及其应用-笔记-模块,包--未完!