Changing default directory
padre last edited by
When I start up notepad, it starts with a default CURRENT_DIRECTORY variable that is pointed to the location where the Notepad++ executable is found. I keep my c files in a different directory. Notepad++ is unable to compile the c-files I have defined because the CURRENT_DIRECTORY variable is set to the wrong place. Is there a way to change the value of the CURRENT_DIRECTORY variable? Thanks.
PeterJones last edited by PeterJones
Welcome, @padre, to the Notepad++ Community forums
In Settings > Preferences > Default Directory, do you have it set to
☑ Follow current document?
Also, what are you using to run the compiler? Run > Run? Or Plugins > NppExec > Run? What command are you passing to that?
If you’re doing something that just relies on one source file and calling in the right directory, Run>Run of
cmd /c gcc "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe"could do it…
For anything more complicated than a one-line command, or anything where directory is critical, I will tend to use NppExec rather than the default Run menu. I usually start with a
cd $(CURRENT_DIRECTORY)to make sure that NppExec’s shell moves to be the same as the directory for the current file. For example, to compile then run a c program using a gcc which is in my path,
npp_save cd "$(CURRENT_DIRECTORY)" gcc "$(FILE_NAME)" -o "$(NAME_PART)" npp_run cmd.exe /k "$(NAME_PART)"
I did a quick experiment: When I have 7.6.4 x64 set to that setting, using Run > Run to
cmd /c echo $(CURRENT_DIRECTORY) && pause, it shows the correct value for the $(CURRENT_DIRECTORY) variable. However, if I switch to
cmd /k echo $(CURRENT_DIRECTORY) && pause, when it drops to the command line, the working directory is the notepad++.exe executable directory instead. SO it definitely needs the CD. I don’t have time at this moment to debug more and get a command that will work in the Run>Run and do the CD before issuing some other command. (Still, like I said, for multi-command sequences, NppExec is better; I also prefer it, because the results window is embedded in Notepad++, rather than spawning an external cmd.exe, which you have to be careful with /k vs /c and
&& pauseto try to keep the results in a window before it disappears.)
PeterJones last edited by
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 && pauseas the command should get what you want.
Really, it would simplify down to
cmd /c cd /d "$(CURRENT_DIRECTORY)" && compiler.exe -o "$(NAME_PART).exe" "$(FILE_NAME)" && pause– I just had the others to show some more placeholders.
But still, if possible, I’d recommend NppExec for anything beyond a one-liner (if it needs
&&to make it work in Run>Run, NppExec will be able to maintain it better)
padre last edited by
Thanks. I seem to have it working now.