Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

shell - Running File from Notepad Plus Plus and Current Directory

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.
')

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 &quot;$(FULL_CURRENT_PATH)&quot;</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 &quot;cd &quot;$(CURRENT_DIRECTORY)&quot; &amp;&amp; &quot;$(FULL_CURRENT_PATH)&quot;&quot;</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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

cmd /k cd /d $(CURRENT_DIRECTORY) && python $(FULL_CURRENT_PATH)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...