Notepad++ open cmd in current file's directory

8

1

Is there a way (probably a macro) how to open cmd in current file's directory?

Say I am editting a file D:\foo\bar.txt and would like to open cmd in D:\foo\. It would really help running various precompilers etc.

mreq

Posted 2012-01-17T19:32:13.997

Reputation: 1 082

Answers

8

Under the Run menu there is an option Open current dir cmd which does exactly what you want.

enter image description here

If your file is on a UNC path then this won't work as it's not possible to cd to a UNC on a command line.

If your source file is on a different drive letter than Notepad++ then it will switch to the correct path but won't switch the drive letter as it appears not to be adding the /D switch to the cd command. However, immediately entering x: Enter (where x is the drive letter where your source file is located) will switch you to the correct path.

You can make the /D default for this by editing the shortcuts.xml file in your user profile (on Win7 it is located in D:\Users\<username>\AppData\Roaming\Notepad++\shortcuts.xml) and adding /D to the Open current dir cmd line:

<Command name="Open current dir cmd" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /K cd /D $(CURRENT_DIRECTORY)</Command>

NB: You cannot edit this file using Notepad++ as it will be overwritten by the in memory options when Notepad++ is closed. Ensure there is no running Notepad++ and edit the xml file using MS Notepad or any other text editor.

(EDIT: Patch submitted to Notepad++ on SourceForge to correct this: http://sourceforge.net/tracker/?func=detail&aid=3475087&group_id=95717&atid=612384)

If you want to assign to a shortcut key select Run -> Modify Shortcut/Delete Command...

enter image description here

enter image description here

Shevek

Posted 2012-01-17T19:32:13.997

Reputation: 15 408

Normally, I had this menu entries before, but in a freshly installed win8.1 instance and notepad++ 6.7 I had to use your answer. Thanks! – Alex. S. – 2014-12-20T22:13:00.483

Which unfortunatelly opens the notepad++ install path. See http://grab.by/bA2T. What could go wrong? I even tried to add the notepad++ folder to the PATH, but that didn't help.

– mreq – 2012-01-17T19:54:51.630

Oh I see your edit and I can confim that on drive_letter: it changes the path correctly. Anyway, that's still odd. Is there a way how to make this work by default (probably edit the macro written somewhere deep in n++)? There would be no harm typing the drive_letter before each cd – mreq – 2012-01-17T20:10:52.393

Thanks for your answer. Strangely, cmd /K cd /D $(CURRENT_DIRECTORY) doesn't work when in shortcuts.xml, while it does work in the shell itself. Dunno what's wrong... – mreq – 2012-01-17T20:32:00.780

1you cannot edit shortcuts.xml using Notepad++ as it will be overwritten again with the in memory values when you exit Notepad++. ensure all Notepad++ are closed then edit using MS Notepad. Ensure you are updating the xml file in your user profile, not the one in the install dir. – Shevek – 2012-01-17T20:55:23.163

1

I found a bug raised for this issue on sourceforge and have submitted a patch: http://sourceforge.net/tracker/?func=detail&aid=3475087&group_id=95717&atid=612384

– Shevek – 2012-01-17T20:56:55.490

it's a pleasure :) – Shevek – 2012-01-17T21:09:19.347

I've updated the answer to include editing using MS Notepad. – Shevek – 2012-01-17T21:11:48.753

2

Run command has moved on later versions of Notepad++ to: Right click on file Tab. i.e. new 1 Select Open Containing Folder in cmd

Also, File->Open Containing Folder->cmd

Sandeep Patel

Posted 2012-01-17T19:32:13.997

Reputation: 21

1

CMD can be opened in the current directory if you pass the arguments to CMD with the Notepad++ syntax:

<Command name="Open current folder in cmd" Ctrl="yes" Alt="yes" Shift="yes" Key="79">cmd /K &quot; cd /D $(CURRENT_DIRECTORY) &quot;</Command>

euans

Posted 2012-01-17T19:32:13.997

Reputation: 11