Home > Backend Development > Python Tutorial > 用python删除java文件头上版权信息的方法

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

WBOY
Release: 2016-06-16 08:42:58
Original
1287 people have browsed it

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

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

# -*- 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!!!!!!!!!!!!!!!'
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template