import os import glob def remove_null_characters_from_html(directory, ignore_files=[], ignore_directories=[]): html_files = glob.glob(os.path.join(directory, '**/*.html'), recursive=True) for file_path in html_files: # ファイルやディレクトリが対象外の場合はスキップ if os.path.basename(file_path) in ignore_files or os.path.dirname(file_path) in ignore_directories: continue with open(file_path, 'r', encoding='utf-8') as file: content = file.read() content = content.replace('\0', '') # null文字を削除 with open(file_path, 'w', encoding='utf-8') as file: file.write(content) if __name__ == "__main__": target_directory = "./build" ignore_files = ["404.html"] ignore_directories = ["assets", "img", ] remove_null_characters_from_html(target_directory, ignore_files, ignore_directories)