Add line of text to beginning of multiple files
-
@PeterJones You sir are a legend, that worked perfectly!!! Thank you so much for taking the time to help me out
-
A lot of people are scared to dip down into the world of batch/CMD/Powershell…
@PeterJones You sir are a legend, that worked perfectly!!!
…and some people are not afraid. :-)
One point of clarification on my previous reply:
@PeterJones had previously stated:
Notepad++ search/replace boxes use a single line for inputting the expression
but my reply concentrated only on the replace box. The reason for that is that if you want to get multiline text that you already have in the Notepad++ window into the “search box”, all you have to do is select it and press ctrl+f (if ctrl+f is so configured – to copy into the box automatically). No conversion of the text (or escaping) is necessary.
UNLESS, you are going to be doing a multiline replacement – in which case you need to be in Regular expression search mode – and your search data contains any of the special regex metacharacters. In this case the best thing to do might be to add a
\Q
at the very start of the “search box”.Yikes, this might be really “obscure”!
-
Glad you got something that worked. I hope you took the opportunity to learn from what @Alan-Kilborn shared as well, because it really is helpful search/replace advice, too.
-----
@Alan-Kilborn said in Add line of text to beginning of multiple files:
I think it’s an OK task for Notepad++.
Well, the 6 lines aren’t bad to encode into the replace box. But when the next poster wants to insert 1023 lines at the beginning of every config file? As I said, “you’re starting to move beyond” (emphasis added): inserting 6 lines at the beginning of 300 files has started down the slippery slope out of the realm of pure text-editor, but not so far that it’s not doable.
Pythonscript, … It takes the currently selected text, formats it correctly, and puts the result in the clipboard, ready for pasting into the Replace with box
I didn’t read correctly / realize what you were doing there until the second read: that’s just cool.
A side question, unrelated to OP: why create an object with the
__init__
, rather than just have aT11987()
function instead?my reply concentrated only on the replace box. … No conversion … necessary
True enough.
-
@PeterJones said in Add line of text to beginning of multiple files:
inserting 6 lines at the beginning of 300 files has started down the slippery slope out of the realm of pure text-editor
Agreed. Maybe that’s why I said it’s an “OK” task for Notepad++ and not “a great” task. :-)
why create an object with the init, rather than just have a T11987() function instead?
It’s just my new framework for scripts (I copy from some boilerplate when I make a new script). Obviously in this case it is fairly trivial, but in scripts that use callbacks a object-based approach has bigger benefits. I picked up on this by observing how @Ekopalypse does some of the more complicated scripts he’s presented. BTW, I picked up on using the topic/posting id in the name of a script/function/class from YOU. :-)