Hi, looking for a regex that calculates distance between 2 numbers, then adjust the 2nd number to a minimum of 30.
-
I think you’re off-track.
This forum is about Notepad++ and its plugins.
We thought we were talking about PythonScript.
But apparently this has evolved into something that doesn’t relate to Notepad++, so we can’t continue to support you here.If you want to continue on with Python, suggest you find a Python forum to keep going with your questions.
-
The script I wrote above can’t be run except through PythonScript in Notepad++. It does not work like a normal Python script. If you want to start a chat with me, I can help you write a normal, non-PythonScript-based Python script to solve your problem in a way that’s unrelated to Notepad++.
-
@Mark-Olson Hi again Mark. I was just successful at getting the script to run in Notepad++ and the PythonScript plugin (yeah). I had a folder of 77 files and I needed to open each file separately and run the script on each and save. It corrected my files perfectly. I have hundreds more to process though. Is there anyway to run the script on the entire folder at once?
-
@Jeff-Michaels
Glad you got it to work! Unfortunately, PythonScript isn’t very well-equipped to manipulate the file system outside of Notepad++. You could in principle write a solution that opened every file in the directory in Notepad++, applied my script above, closed the file, and moved on to the next. However, that would be very slow compared to just writing a normal Python script that doesn’t use Notepad++ at all.Since my preferred solution to your larger problem doesn’t use Notepad++, I’ll turn to the chat.
-
@Mark-Olson Do you have a preferred way to chat or email? my email is jeff@sybersound.com
-
Just want to close by making a general note for posterity.
Out of curiosity, I tried using ChatGPT with Jeff’s problem, and it provided a solution that was suboptimal but serviceable nonetheless. And of course it was much much faster than me.
So I guess what I’d say is this:
If you’re looking for guidance on how to solve a problem that requires Notepad++, you’ve come to the right place. Not only that, I would very strenuously advise against trusting anything that ChatGPT says about Notepad++. However, if you don’t have any particular reason to believe that Notepad++ needs to be in the loop, ChatGPT might potentially be useful, as it excels at coming up with decent solutions to simple, routine problems, so long as you check its work. -
To keep the thread on-topic, I see that the OP has things working within Notepad++ and apparently has fixed some of his files using Notepad++ with Notepad++'s flavor of PythonScript.
The OP then asked if there is a way to do the script on all of the files in a folder. I believe it’s possible but don’t know the best practice for 1) How can someone open dozens, hundreds, or thousands of files in Notepad++? 2) How can someone then run a particular PythonScript from within Notepad++ on all open tabs?
To address #1 something I do is to construct a Notepad++ session file that has all of the files that I want to work on and then run Notepad++.exe with
-openSession filename
. While that works for me I don’t know if that’s the best practice. It may well be the OP is satisfied with runningNotepad.exe *.txt
from the command line and letting Notepad++'s build in wild card expansion take over. I just tried it on a folder with 963 files and … a minute later had 963 new tabs open. I was surprised that “close all tabs to the right” took about 45 seconds but it worked.I don’t know how to address #2 - Is it possible to run a PythonScript on all open tabs?
-
@mkupper said in Hi, looking for a regex that calculates distance between 2 numbers, then adjust the 2nd number to a minimum of 30.:
Is it possible to run a PythonScript on all open tabs?
No. What you would do is, in a single run of a single script, iterate over the open file tabs:
for (filename, bufferID, index, view) in notepad.getFiles(): notepad.activateFile(filename) ....
After a file is “activated”, then the
editor
object can manipulate the data of the activated tab, e.g., perhaps do aneditor.replace()
, etc. -
This post is deleted! -
This post is deleted!