Community
    • Login

    using regex to identify and insert full path

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 502 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.
    • Tat UbuT
      Tat Ubu
      last edited by

      I’m hoping someone here has a name for the task I’m trying to do.

      I want to append the full path for each of 3000 text files as the last line in each file. Part of that is easy. What puzzles me is whether NPP can extract the full path if it isn’t already spelled out in the file. I’m hoping there’s a native way that NPP knows the path/UNC of a given file, and that I can call it as part of a regex statement

      Does NPP have a way of identifying and copying the directory structure/ UNC path? What’s it called?

      Terry RT 1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R @Tat Ubu
        last edited by

        @Tat-Ubu said in using regex to identify and insert full path:

        I’m hoping there’s a native way that NPP knows the path/UNC of a given file, and that I can call it as part of a regex statement

        Regex cannot call upon the “source directory” of the file being worked. However NPP does have that information and through the use of macro’s you could insert that into the file at the end of the file.

        Firstly you may want to read an old post I had a solution posted in that is similar to your request. Given it was 4 years old there may be a better way now, but this can be a good starting point for your question. It’s here.

        Terry

        Tat UbuT Terry RT 2 Replies Last reply Reply Quote 1
        • Tat UbuT
          Tat Ubu @Terry R
          last edited by

          @Terry-R Thank you for that.
          I had read through that post before adding mine.
          GreatMindsThinkAlike (well, maybe).

          Anyway, here’s a more specific question: can I use NPPExec to provide the UNC?

          If I use the Exec console to list the current directory, I get that information on the console screen. Is there a way to auto-extract that detail and paste it into the file?

          Terry RT 1 Reply Last reply Reply Quote 0
          • Terry RT
            Terry R @Terry R
            last edited by

            @Terry-R said in using regex to identify and insert full path:

            Given it was 4 years old there may be a better way now,

            I have just tested again based on that old post. If you look at the main menu “Edit”, then “Copy to Clipboard” you will see some options on the path and filename of the file currently being worked on. You select one to copy to clipboard. Then in that file, you Ctrl-End to position the cursor at the last position. I suggest at this point you would hit “enter” once to create a newline. Then Ctrl-V to paste that information (filename and/or path).

            All this can be recorded as a macro. This is from the Macro main menu. I suggest if you’ve never done macro’s before you read the online manual here. It can sometimes take a few attempts to get the understanding of macros right so that what you record will actually do the job you ask, so a bit of perseverance is sometimes warranted.

            Terry

            Tat UbuT 1 Reply Last reply Reply Quote 2
            • wonkawillyW
              wonkawilly
              last edited by wonkawilly

              You can get the current file path from menu > Edit Copy to Clipboard > Copy Current File Path

              A screenshots follows:

              8b24e287-9a13-4423-b08d-a16aac0a5681-image.png

              About your request IMHO you have more than one option:

              • a macro
              • a script, for example in Python
                In the first case you don’t need else than Npp but it could be problematic to implement.
                In the second case you will need to install a plugin that is able to run scripts into Notepad++. This last possibility is IMHO the way to go.

              About that another screenshot follows:

              0e7b0cb2-71c8-4ae5-af46-db5e0a955e15-image.png

              Tat UbuT 1 Reply Last reply Reply Quote 1
              • Terry RT
                Terry R @Tat Ubu
                last edited by Terry R

                @Tat-Ubu said in using regex to identify and insert full path:

                Anyway, here’s a more specific question: can I use NPPExec to provide the UNC?

                I dare say you could, and some members here are quite proficient with NPPExec, not me though. However I would suggest you may well have a larger learning curve to get that to work than my answer above.

                Terry

                1 Reply Last reply Reply Quote 0
                • Tat UbuT
                  Tat Ubu @Terry R
                  last edited by

                  @Terry-R
                  Now that’s almost too easy!
                  Do I have an excuse for not looking through the menu options? :)

                  Anyway, I’ve done a few macros in the past, so that’s also an easy task. And it happens that Alt+S is already the shortcut I want.

                  So far so good!

                  1 Reply Last reply Reply Quote 1
                  • Tat UbuT
                    Tat Ubu @wonkawilly
                    last edited by

                    @wonkawilly

                    https://
                    postimg(dot)cc
                    /wtTRQT2F

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