Method to remove copyright information in the header of a Java file in python
- 2020-04-02 13:57:08
- OfStack
When using other people's code, in order not to retain the file header copyright information, need to delete one by one, time-consuming and laborious,
Wrote a script, simply clear the directory of all files header copyright information.
# -*- coding: utf8 -*-
'''''
delete java Notes such as copyright in the head of the file
package Upper part
'''
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!!!!!!!!!!!!!!!'