• Login
Community
  • Login

Convert multiple files from UTF-8 to ANSI

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 3 Posters 36.9k Views
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.
  • V
    Vasile Caraus
    last edited by Vasile Caraus Sep 18, 2016, 5:16 PM Sep 18, 2016, 5:15 PM

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

    1 Reply Last reply Reply Quote 0
    • V
      Vasile Caraus
      last edited by Vasile Caraus Sep 21, 2016, 3:16 AM Sep 21, 2016, 3:16 AM

      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
      • M
        Maxim Chartrand
        last edited by Maxim Chartrand Feb 24, 2017, 11:38 PM Feb 24, 2017, 11:38 PM

        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
        • M
          Maxim Chartrand
          last edited by Maxim Chartrand Feb 25, 2017, 12:05 AM Feb 25, 2017, 12:02 AM

          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
          
          S 1 Reply Last reply Feb 25, 2017, 12:42 AM Reply Quote 0
          • S
            Scott Sumner @Maxim Chartrand
            last edited by Feb 25, 2017, 12:42 AM

            @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
            • M
              Maxim Chartrand
              last edited by Feb 25, 2017, 1:25 AM

              @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
              • M
                Maxim Chartrand
                last edited by Feb 26, 2017, 2:53 AM

                Correction to the second solution :

                    nested_levels = root.split('\\')
                    if len(nested_levels) == 2:
                
                1 Reply Last reply Reply Quote 0
                • V
                  Vasile Caraus
                  last edited by Feb 26, 2017, 2:51 PM

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

                  1 Reply Last reply Reply Quote 0
                  • V
                    Vasile Caraus
                    last edited by Feb 26, 2017, 3:06 PM

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