using regex to identify and insert full path
-
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?
-
@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
-
@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-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
-
You can get the current file path from menu > Edit Copy to Clipboard > Copy Current File Path
A screenshots follows:
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:
-
@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
-
@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!
-
https://
postimg(dot)cc
/wtTRQT2F