vonzyy Posted March 30 Posted March 30 (edited) I have a lot of "utf-8" files and want to convert them to "utf-16 le bom" quickly. Is there a script that can do it? Edited Sunday at 12:38 PM by vonzyy
CaptJack Posted April 4 Posted April 4 Try spare into 2 files more than one. Atleast don't sell the machine translation
vonzyy Posted Sunday at 12:40 PM Author Posted Sunday at 12:40 PM On 4/4/2025 at 4:43 PM, CaptJack said: Try spare into 2 files more than one. Atleast don't sell the machine translation No, mate. I'm not selling it.
Moderators ikskoks Posted Monday at 06:20 PM Moderators Posted Monday at 06:20 PM This Python script should do the trick: import os def convert_to_utf16(input_path: str, output_path: str) -> None: print("Starting convert...") with open(input_path, 'rt', encoding='utf-8') as f_in: content = f_in.read() with open(output_path, 'wb') as f_out: f_out.write(b'\xff\xfe') f_out.write(content.encode('utf-16-le')) print("Convert success!") def convert_all_txt_in_folder(input_folder: str, output_folder: str) -> None: os.makedirs(output_folder, exist_ok=True) for filename in os.listdir(input_folder): if filename.lower().endswith('.txt'): input_path = os.path.join(input_folder, filename) base_name = os.path.splitext(filename)[0] output_filename = f"{base_name}_utf16le.txt" output_path = os.path.join(output_folder, output_filename) convert_to_utf16(input_path, output_path) print(f'Converted: {filename} -> {output_filename}') if __name__ == '__main__': convert_all_txt_in_folder('C:\\Users\\User\\Desktop\\UTF_FILES\\input', 'C:\\Users\\User\\Desktop\\UTF_FILES\\output')
vonzyy Posted Tuesday at 04:24 AM Author Posted Tuesday at 04:24 AM 10 hours ago, ikskoks said: This Python script should do the trick: import os def convert_to_utf16(input_path: str, output_path: str) -> None: print("Starting convert...") with open(input_path, 'rt', encoding='utf-8') as f_in: content = f_in.read() with open(output_path, 'wb') as f_out: f_out.write(b'\xff\xfe') f_out.write(content.encode('utf-16-le')) print("Convert success!") def convert_all_txt_in_folder(input_folder: str, output_folder: str) -> None: os.makedirs(output_folder, exist_ok=True) for filename in os.listdir(input_folder): if filename.lower().endswith('.txt'): input_path = os.path.join(input_folder, filename) base_name = os.path.splitext(filename)[0] output_filename = f"{base_name}_utf16le.txt" output_path = os.path.join(output_folder, output_filename) convert_to_utf16(input_path, output_path) print(f'Converted: {filename} -> {output_filename}') if __name__ == '__main__': convert_all_txt_in_folder('C:\\Users\\User\\Desktop\\UTF_FILES\\input', 'C:\\Users\\User\\Desktop\\UTF_FILES\\output') Sorry, how to use the script. I have tried to put the script into python but the script still doesn't work.
Moderators ikskoks Posted Tuesday at 04:43 PM Moderators Posted Tuesday at 04:43 PM You execute it like any other Python script https://www.google.com/search?client=firefox-b-d&q=how+to+run+python+script python script.py
Sparagas Posted 15 hours ago Posted 15 hours ago On 5/6/2025 at 7:24 AM, vonzyy said: Sorry, how to use the script. I have tried to put the script into python but the script still doesn't work. On Windows you just double click it like normal .exe file
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now