Ways to remove copyright information from Java file headers with Python

Source: Internet
Author: User
In the use of other people's Code, to not retain the file header copyright information, need to delete, time-consuming and laborious,

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

#-*-Coding:utf8-*-"Remove the copyright in the header of the Java file and other comments above the package" ' Import OS import sys def delheader (filepath): if Os.path.ex Ists (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!!!!!!!!!!!!!!! '
  • 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.