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

python 遍历指定文件夹下的所有文件内容

2015-09-17 17:55 411 查看
最近公司代码需要做版权审查需要一些代码,足足60页的word文档,
如果一个一个文件的copy代码 就真是out,最近在学习python,就写了个python的脚本,方便上面操作。

__author__ = 'jghost'

import os

for root,dirs,files in os.walk('your source'):
print root #path
for name in files:
if name.endswith('.java'):
dic = open('/home/jghost/filefilter.txt','a')
dic.write('\n')
dic.write('\n')
dic.write(name+'\n')
dic.write('#author:jgost\n')
dic.write('#company:xxxx\n')
source = open(root+'/'+name)
while True:
context = source.readline()
if context.strip().startswith('#'):
continue
dic.write(context)
if not context:
break
source.close()
dic.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: