# -*- encoding:utf-8 -*-
#==================================
# 当前文件所在文件夹下所有以JC打头的文件
#==================================
import os
if __name__ == '__main__' :
# 为所有文件第一行加上 # -*- encoding:gbk -*-
folder_path = os.path.dirname(__file__)
files = os.listdir(folder_path)
for file_name in files:
if file_name.startswith( 'JC' ):
file_path = os.path.join(folder_path, file_name)
if os.path.exists(file_path):
lines = ['# -*- encoding:gbk -*-\n\n' ]
# read
file_object = open(file_path)
read_lines = file_object.readlines()
if read_lines:
if read_lines[0] == '# -*- encoding:gbk -*-\n' :
continue
else:
continue
for line in read_lines:
lines.append(line)
# write
file_object = open(file_path, 'w' )
for line in lines:
file_object.write(line)
file_object.close()