Created
May 24, 2023 07:57
-
-
Save gklein/5d5fbb0f73beb2f8b105859c550f1c4f to your computer and use it in GitHub Desktop.
Qtext to TXT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import codecs | |
from bidi.algorithm import get_display | |
for file in os.listdir("."): | |
print(file) | |
ext = os.path.splitext(file)[1] | |
if os.path.isfile(file) and ext.startswith(".H"): | |
print(f"Processing ", {file}) | |
filename = os.path.join(".", file) | |
# Create temp file with codecs.BOM_UTF8 prefix | |
tmp_file = file + ".tmp" | |
tmp_filename = os.path.join(".", tmp_file) | |
# Open original file and temp file | |
with open(filename, "rb") as f_in, open(tmp_filename, "wb") as f_out: | |
# Add UTF-8 BOM | |
f_out.write(codecs.BOM_UTF8) | |
# Convert and write to temp file | |
for line in f_in: | |
f_out.write(get_display(line.decode("ibm862").encode("utf-8"))) | |
shutil.move(tmp_filename, filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment