i want insert
# -*- coding: utf-8 -*-
to multi file's first line in multi path (include sub directory and diff directory) when i use open + whrite python code the result will be append to bottom
import os
def show_folder_content(folder_path):
folder_content = os.listdir(folder_path)
for item in folder_content:
if os.path.isdir(folder_path + '\\' + item):
print('folder:' + item)
show_folder_content(folder_path + '\\' + item)
elif os.path.isfile(folder_path + '\\' + item):
print('file:' + item)
f = open(folder_path + '\\' + item, "a")
f.write("\n# -*- coding: utf-8 -*-")
f.close()
else:
print('other:' + item)
target_folder = 'F:\\project\\test_source'
show_folder_content(target_folder)
how to append the top of all files (first line) cause' i want bath make my code support utf8