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!
Kosmoshuynh
-
@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 therenameoption. I’m not actually able to provide the answer but I googledrename multiple files in sub foldersand 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
-
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
-
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()
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