Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    notepad.saveAs multiple files in a folder including subfolders?

    Help wanted · · · – – – · · ·
    3
    4
    241
    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.
    • Kosmos Huynh
      Kosmos Huynh last edited by

      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
      • Terry R
        Terry R last edited by

        @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

        Kosmos Huynh 1 Reply Last reply Reply Quote 1
        • Kosmos Huynh
          Kosmos Huynh @Terry R last edited by

          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

          Ekopalypse 1 Reply Last reply Reply Quote 0
          • Ekopalypse
            Ekopalypse @Kosmos Huynh last edited by

            @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
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors