在使用他人代码时,为不保留文件头部版权信息,需要一个个删掉,费时费力,
写了个脚本,简单清除掉目录下所有的文件的头部版权信息。
# -*- 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!!!!!!!!!!!!!!!'
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8