notepad.saveAs multiple files in a folder including subfolders?

  • 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!


  • @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.


  • 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

  • @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)

Log in to reply