• Login
Community
  • Login

notepad.saveAs multiple files in a folder including subfolders?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 720 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.
  • K
    Kosmos Huynh
    last edited by Sep 11, 2020, 2:03 AM

    Dear Experts,

    I am struggling with the problem as the following:

    • I have a folder (named A) contains 20 subfolders.
    • In each subfolder, there are about 5,000 *.mht files that only text. The *.mth files were edited and remain only text.
    • In total, there are 100,000 *.mht files in folder A.
    • I open each *.hmt file and then I can easily save as a *.txt file. However, it will take me… years 😭😭😭 with that.
      ==> My idea is that I want to use “notepad.saveAs” function to help me out. However, I do not know how to do with that function.

    Do you have any experience of that? If yes, you kindly please give me a favor.

    I appreciate your help in advance!

    Kosmoshuynh

    1 Reply Last reply Reply Quote 0
    • T
      Terry R
      last edited by Sep 11, 2020, 3:45 AM

      @Kosmos-Huynh said in notepad.saveAs multiple files in a folder including subfolders?:

      I open each *.hmt file and then I can easily save as a *.txt file.

      I don’t have experience with what you are trying in Notepad++, however I think that is the wrong way to do it.
      There is no need to open the files, Windows can do it with the rename option. I’m not actually able to provide the answer but I googled rename multiple files in sub folders and came up with multiple solutions.

      As the solutions involve some code over multiple lines you may still want to use Notepad++ to help create the file that stores the code.

      Terry

      K 1 Reply Last reply Sep 11, 2020, 7:44 AM Reply Quote 1
      • K
        Kosmos Huynh @Terry R
        last edited by Sep 11, 2020, 7:44 AM

        Dear @Terry-R and all,

        Many thanks for your quick response. I tried with your suggested method before but it did not work.

        • The main problem was that they totally my texts became weird. However, I open mhtml (mht) with NP++ and save as *.txt that it worked perfectly.
        • I have tried with macro but they also did work. So, I think about a solution with “python script” plugin, especially notepad.saveAs() function. However, I have never tried and experienced.
          Hopefully, my question will come up with solutions to experts from our community.

        Kosmos Huynh

        E 1 Reply Last reply Sep 11, 2020, 9:30 AM Reply Quote 0
        • E
          Ekopalypse @Kosmos Huynh
          last edited by Sep 11, 2020, 9:30 AM

          @Kosmos-Huynh

          Something like this should do what you try to achieve

          from Npp import notepad
          import os
          
          root_directory = r'C:\xyz\xyz\A'
          
          for _dir, _, _files in os.walk(root_directory):
              for _file in _files:
                  if _file.endswith('.mht'):
                      __file = os.path.join(_dir, _file)
                      notepad.open(__file)
                      notepad.saveAs(__file.replace('.mht','.txt'))
                      notepad.close()
          
          1 Reply Last reply Reply Quote 1
          1 out of 4
          • First post
            1/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors