diff options
author | 安竹洋平 <61961825+yasutakeyohei@users.noreply.github.com> | 2024-01-21 22:47:03 +0900 |
---|---|---|
committer | 安竹洋平 <61961825+yasutakeyohei@users.noreply.github.com> | 2024-01-21 22:47:03 +0900 |
commit | ed368ccb29bbc51a6d897bee27094309f62f788f (patch) | |
tree | 352d8ca50385c568cd2228f1db3673d33d777aa1 /removeNullCharacters.py | |
parent | 8631539a427584dd73164e3dd888f4c6f64d4394 (diff) |
initial commit
Diffstat (limited to 'removeNullCharacters.py')
-rw-r--r-- | removeNullCharacters.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/removeNullCharacters.py b/removeNullCharacters.py new file mode 100644 index 00000000..bd7d0a95 --- /dev/null +++ b/removeNullCharacters.py @@ -0,0 +1,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)
\ No newline at end of file |