用python删除java文件头上版权信息的方法

yipeiwu_com7年前Python基础

在使用他人代码时,为不保留文件头部版权信息,需要一个个删掉,费时费力,

写了个脚本,简单清除掉目录下所有的文件的头部版权信息。

# -*- coding: utf8 -*- 
''''' 
删除java文件头部的版权等注释 
package之上的部分 
''' 
import os 
import sys 

def delHeader(filepath): 
if os.path.exists(filepath) : 
file = open(filepath) 
lines = file.readlines() 
beforeTag = True 
writer = open(filepath, 'w') 
for line in lines : 
if 'package' in line: 
beforeTag = False 
if beforeTag == False: 
writer.write(line) 

if __name__ == '__main__': 
path='F:\\space\\xxx\\src' 
list = os.walk(path, True) 
for dir in list: 
files = dir[2] 
for file in files : 
if '.java' in file : 
filepath = os.path.join(dir[0], file) 
print filepath 
delHeader(filepath) 

print 'Complete!!!!!!!!!!!!!!!'

相关文章

python把数组中的数字每行打印3个并保存在文档中的方法

python把数组中的数字每行打印3个并保存在文档中的方法

如下所示: arrs=[2,15,48,4,5,6,7,6,4,1,2,3,6,6,7,4,6,8] f=open('test.txt','w+') count=0 for temp...

python实现将内容分行输出

#python版一行内容分行输出   a="aA1一bB2二cC3三dD4四eE5五fF6六gG7七hH8八iI9九" """ 分行输出为: abcdefghi ABCD...

python字典排序实例详解

本文实例分析了python字典排序的方法。分享给大家供大家参考。具体如下: 1、 准备知识: 在python里,字典dictionary是内置的数据类型,是个无序的存储结构,每一元素是k...

Random 在 Python 中的使用方法

Random 在 Python 中的使用方法

1.random.random(): 会随机生成0-1之间的小数 例如: 2.random.uniform(min,max): 会随机生成 min - max 之间的小数,其中min...

Python实现的数据结构与算法之链表详解

Python实现的数据结构与算法之链表详解

本文实例讲述了Python实现的数据结构与算法之链表。分享给大家供大家参考。具体分析如下: 一、概述 链表(linked list)是一组数据项的集合,其中每个数据项都是一个节点的一部分...