How to remove copyright information from the Java file header in Python _python

Source: Internet
Author: User
Tags in python

In the use of other people's Code, in order not to retain the file head copyright information, need to delete one by one, time-consuming and laborious,

Write a script that simply clears the header copyright information for all files in the directory.

#-*-Coding:utf8-*- 
' 
Delete the Java file header's Copyright Annotation 
package Section 
' 
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 ' on line: 
Beforetag = Fa LSE 
If Beforetag = = False: 
writer.write (line) 

if __name__ = ' __main__ ': 
path= ' f:\\space\\xxx\\  src ' 
list = Os.walk (path, True) for 
dir-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!!!!! !!!!!!!!!!'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.