There are a number of examples on the web of how to run a file from the Notepad Plus Plus (NPP). But they all fail to account for the fact that the current working directory is the location of the NPP's executable, and not the location of the file.
Usually they go something like this:
cmd /K "$(FULL_CURRENT_PATH)"
Consider the following Python script:
with open('somefile.txt', 'a') as file:
file.write('Hello there.\n')
This file will be created in the NPP folder, which is not at all what most people would expect. Most people would want it in the same location as the Python file.
You could also do something like this, and it works as expected, but this limits you to Python files only:
<Command name="Run This Python File" Ctrl="no" Alt="no" Shift="yes" Key="116">cmd /K python "$(FULL_CURRENT_PATH)"</Command>
I would not want to add extra code to the Python script to change the current working directory, as normally this would not be needed.
I have been trying to solve this and came up with the following. This line goes in "shortcuts.xml" in the NPP folder.
<Command name="Run This File" Ctrl="yes" Alt="no" Shift="no" Key="116">cmd /K "cd "$(CURRENT_DIRECTORY)" && "$(FULL_CURRENT_PATH)""</Command>
So you shut down the NPP, edit the "shortcuts.xml" by adding this line, using another editor, then launch the NPP. To run the file, use Ctrl+F5 key combination.
This works in Windows 10, but fails in Windows XP.
How can I tweak it to work in Windows XP?
Okay, able to revisit for a couple more minutes: if you need it to be in Run > Run rather than NppExec, starting from cmd /c cd /d "$(CURRENT_DIRECTORY)" && dir "$(FILE_NAME)" && echo change the dir and this last echo into just the compiler.exe -o "$(NAME_PART).exe" "$(FILE_NAME)" or whatever && pause as the command ...
Run -> Run (F5) Type command line into "The Program to Run" Save, type the name (choose the shortcut if you need)
If no cloud location is specified (see above), Notepad++ stores its settings files in %AppData%\Notepad++ , which resides in the user profile. The location of the settings files can be moved to the installation directory by creating the file DoLocalConf.
Instructions: Click the Menu "Run -> Run..." (or alternatively hit F5) Enter "$(FULL_CURRENT_PATH)" in the field (without quotes) Click "Save..."
Try this:
cmd /k cd /d $(CURRENT_DIRECTORY) && python $(FULL_CURRENT_PATH)
My guess would be that the problem is the improperly nested quotes in the command; I'm not sure exactly why it would work on later Windows' while failing on XP.
The command
cmd /K "cd "$(CURRENT_DIRECTORY)" && "$(FULL_CURRENT_PATH)""
represents
cmd /K "cd "$(CURRENT_DIRECTORY)" && "$(FULL_CURRENT_PATH)""
Even from the syntax highlighting you can see that the quotes are not quoting what you expect.
To get the desired effect, you can use this command:
cmd /K cd "$(CURRENT_DIRECTORY)" ^&^& "$(FULL_CURRENT_PATH)"
:: XML-ified:
cmd /K cd "$(CURRENT_DIRECTORY)" ^&^& "$(FULL_CURRENT_PATH)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With