aboutsummaryrefslogtreecommitdiff
path: root/removeNullCharacters.py
blob: bd7d0a954b609cfff8f4904afe962e397df7f564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)