项目开发过程与到一个小事情,由于需要修改license,但是整个项目之前每个file文件都有
# @license: Apache Licence
标记,因此需要删除全部文件的标记,手工重复耗时。python 脚本高效。
#!/usr/bin/env python
# encoding: utf-8
# @file: delete license.py
# @time: 2017/11/3 11:37
# @author: FunnyWu
# @contact: agiot1026@163.com
# @Software: PyCharm
import os
root_path = "E:\Work\CrawlerPlatform"
def list_file(path):
if os.path.isdir(path):
for i in os.listdir(path):
path_dir = os.path.join(path, i)
list_file(path_dir)
elif '.py' in path and '.pyc' not in path:
change_file_header(path)
def change_file_header(path):
fp = open(path, 'r', encoding='utf-8')
content = fp.readlines()
fp.close()
flag = False
for line in content:
if '# @license: Apache Licence ' in line:
flag = True
content.remove(line)
if flag:
print('change: ', path)
with open(path, 'w', encoding='utf-8')as fp:
fp.writelines(content)
if __name__ == '__main__':
print()
list_file(root_path)