Convert multiple files from UTF-8 to ANSI
-
hello, does anybody know how to convert 200 files from UTF-8 to ANSI ?
-
there is a nice and useful program, name “Cp Converter” (Codepage Converter) the same thing. This will do all the encoding converts for multiple files.
-
Hello,
I was looking for a way to do it in NPP. I found a solution with a Python script (see below) but I’m looking for a way to limit the depth of os.walk method. I want to apply the conversion to HTML files located in the first level only, excluding those in subdirectories. Can someone help on this? Thanks.
https://pw999.wordpress.com/2013/08/19/mass-convert-a-project-to-utf-8-using-notepad/
Maxim
-
Here is the script :
import os; import sys; Path="C:\\python-test" for root, dirs, files in os.walk(Path): for filename in files: if filename[-5:] == '.html': notepad.open(root + "\\" + filename) console.write(root + "\\" + filename + "\r\n") notepad.runMenuCommand("Encodage", "Convertir en ANSI") notepad.save() notepad.close()Results:
(I want to exclude : files in subdirectories below python-test folder)C:\python-test\fichier1.html C:\python-test\fichier2.html C:\python-test\python-folder\fichier3.html -
Perhaps the quickest way to modify it to do what you want would be adding a single line below the os.walk() line:
for root, dirs, files in os.walk(Path): if root == Path: -
Thank you very much, I will use your solution.
I just found another solution here :
http://stackoverflow.com/questions/17493271/limit-the-number-of-nested-directories-traversed-by-os-walkHere is my code, maybe it will helps someone else with a different need.
import os; import sys; Path="C:\\python-test" for root, dirs, files in os.walk(Path): nested_levels = root.split('/') if len(nested_levels) > 0: del dirs[:] for filename in files: if filename[-5:] == '.html': notepad.open(root + "\\" + filename) console.write(root + "\\" + filename + "\r\n") notepad.runMenuCommand("Encodage", "Convertir en UTF-8") notepad.save() notepad.close() -
Correction to the second solution :
nested_levels = root.split('\\') if len(nested_levels) == 2: -
hello. How can I run this python codes to all files from a folder?
-
I run this code with python.exe on win10. I only change the path, and I want to test it. But after I copy the code on python.exe, nothing happen.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login