Community
    • Login

    Convert multiple files from UTF-8 to ANSI

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 3 Posters 38.2k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Vasile CarausV Offline
      Vasile Caraus
      last edited by Vasile Caraus

      hello, does anybody know how to convert 200 files from UTF-8 to ANSI ?

      1 Reply Last reply Reply Quote 0
      • Vasile CarausV Offline
        Vasile Caraus
        last edited by Vasile Caraus

        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.

        https://sourceforge.net/projects/cp-converter/

        1 Reply Last reply Reply Quote 0
        • Maxim ChartrandM Offline
          Maxim Chartrand
          last edited by Maxim Chartrand

          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

          1 Reply Last reply Reply Quote 0
          • Maxim ChartrandM Offline
            Maxim Chartrand
            last edited by Maxim Chartrand

            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
            
            Scott SumnerS 1 Reply Last reply Reply Quote 0
            • Scott SumnerS Offline
              Scott Sumner @Maxim Chartrand
              last edited by

              @Maxim-Chartrand

              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:
              
              1 Reply Last reply Reply Quote 0
              • Maxim ChartrandM Offline
                Maxim Chartrand
                last edited by

                @Scott-Sumner

                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-walk

                Here 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()
                
                1 Reply Last reply Reply Quote 0
                • Maxim ChartrandM Offline
                  Maxim Chartrand
                  last edited by

                  Correction to the second solution :

                      nested_levels = root.split('\\')
                      if len(nested_levels) == 2:
                  
                  1 Reply Last reply Reply Quote 0
                  • Vasile CarausV Offline
                    Vasile Caraus
                    last edited by

                    hello. How can I run this python codes to all files from a folder?

                    1 Reply Last reply Reply Quote 0
                    • Vasile CarausV Offline
                      Vasile Caraus
                      last edited by

                      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.

                      1 Reply Last reply Reply Quote 0

                      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
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors