zoukankan      html  css  js  c++  java
  • python 遍历指定文件夹下的所有文件内容

    最近公司代码需要做版权审查需要一些代码,足足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('
    ')
                dic.write('
    ')
                dic.write(name+'
    ')
                dic.write('#author:jgost
    ')
                dic.write('#company:xxxx
    ')
                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()
  • 相关阅读:
    每种特定的迭代器如何使用
    常量迭代器
    容器迭代器
    三十分钟掌握STL
    高快省的排序算法
    FloatTest32 Example
    /浮点数的比较
    java第一天
    ACwing 898
    POJ 3268
  • 原文地址:https://www.cnblogs.com/Jghost/p/3643173.html
Copyright © 2011-2022 走看看