Community
    • Login

    How to save 1000+ fills at once?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 891 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.
    • Junuk SeoJ
      Junuk Seo
      last edited by

      Hi there.

      I have over 1000+ txt files that I have been using for several years.

      I can save them via Ctrl + Alt + S, but I have a problem with having to click the save button each time.

      Is there a way to just click and have all the files saved to a specific directory or to Notepad’s backup directory?

      Thank you.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Junuk Seo
        last edited by

        @Junuk-Seo

        The only good way I can think of to achieve this is via a bit of scripting; here’s a script snippet showing the base logic:

                folder_for_save = r'C:\TEST__SaveABunchOfNewXFiles'
                if not os.path.isdir(folder_for_save):
                    print('folder does not exist: "{}" -- aborting!'.format(folder_for_save))
                else:
                    for (pathname, buffer_id, index, view) in notepad.getFiles():
                        if os.path.isfile(pathname): continue
                        path_for_save = folder_for_save + os.sep + pathname + '.txt'
                        if os.path.isfile(path_for_save): continue
                        notepad.activateFile(pathname)
                        cfn = notepad.getCurrentFilename()
                        if cfn != pathname:
                            print('switching to "{}" for saving was not successful -- skipping!'.format(pathname))
                            continue
                        notepad.saveAs(path_for_save)
        
        Junuk SeoJ 1 Reply Last reply Reply Quote 4
        • Mark OlsonM
          Mark Olson
          last edited by

          …although if you’re already using a scripting language to automate this process as AlanKilborn suggested, you should probably just be using the scripting language to work directly with massive numbers of files, rather than getting Notepad++ involved.

          Alan KilbornA 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @Mark Olson
            last edited by

            @Mark-Olson said in How to save 1000+ fills at once?:

            …although if you’re already using a scripting language to automate this process as AlanKilborn suggested, you should probably just be using the scripting language to work directly with massive numbers of files, rather than getting Notepad++ involved.

            We really don’t know what OP is doing.
            We trust OP knows what they are doing and has “good procedures” in place. :-)
            We just try to answer what is asked, and provide workarounds when Notepad++ itself doesn’t meet the requested need.

            1 Reply Last reply Reply Quote 3
            • Junuk SeoJ
              Junuk Seo @Alan Kilborn
              last edited by

              Hi, @Alan-Kilborn

              Thanks for the answer!

              After installing the Python Script plugin, I just changed the path in the script you commented, saved it to startup.py and ran it, but it didn’t work.

              Is this script just a sample? I don’t have any programming knowledge so I’m not sure.

              Thank you!

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @Junuk Seo
                last edited by Alan Kilborn

                @Junuk-Seo said in How to save 1000+ fills at once?:

                I just changed the path in the script

                Good.

                saved it to startup.py

                Not sure why you would do this. You should give the script its own file (suggest: SaveABunchOfNewXFiles.py) and run it on-demand from the PythonScript menu when you need it.

                Is this script just a sample?

                Yes, the intent was to just show the relevant logic.

                A complete, runnable script is:

                # -*- coding: utf-8 -*-
                from __future__ import print_function
                
                from Npp import *
                import os
                
                folder_for_save = r'C:\TEST__SaveABunchOfNewXFiles'
                if not os.path.isdir(folder_for_save):
                    print('folder does not exist: "{}" -- aborting!'.format(folder_for_save))
                else:
                    for (pathname, buffer_id, index, view) in notepad.getFiles():
                        if os.path.isfile(pathname): continue
                        path_for_save = folder_for_save + os.sep + pathname + '.txt'
                        if os.path.isfile(path_for_save): continue
                        notepad.activateFile(pathname)
                        cfn = notepad.getCurrentFilename()
                        if cfn != pathname:
                            print('switching to "{}" for saving was not successful -- skipping!'.format(pathname))
                            continue
                        notepad.saveAs(path_for_save)
                

                If it still doesn’t work, check the PythonScript console window for any odd output.

                Maybe this FAQ helps you with the basics of scripting.

                Junuk SeoJ 1 Reply Last reply Reply Quote 1
                • Junuk SeoJ
                  Junuk Seo @Alan Kilborn
                  last edited by

                  Hi, @Alan-Kilborn

                  I followed guide as you pointed out and finally got the script running!

                  However, I am getting the error “‘Please check whether this file is opened in another program’”.

                  I tried many ways to solve this problem.

                  Running in admin mode, removing dependencies connected to Winscp, stopping anti-virus programs, closing all windows except notepad …v…v

                  But none of that worked.

                  Is there some permission in the script that I need to set that I’m not aware of?
                  Or is this just something wrong with my windows?

                  Thank you.

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @Junuk Seo
                    last edited by

                    @Junuk-Seo said in How to save 1000+ fills at once?:

                    I am getting the error “‘Please check whether this file is opened in another program’”.

                    This doesn’t make sense as the assumption was that the files are all new 1, new 2, etc files (as otherwise all you need to do is a Save All), and thus these “files” could not be open in another program. Perhaps that was a bad assumption.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors