For example, I want to add notepad++ to my PATH, however the directory also contains
uninstall.exe and several other files/executables and I don't want them to "pollute" my path. Can I just add the one
You can add a batch script to a directory that is in your path, that looks something like this:
@echo off :: Notepad++ execution if [%1]==[-h] goto :HELP if [%1]==[--help] goto :HELP if [%1]==[/?] goto :HELP goto :START :START start "" /i "%ProgramFiles(x86)%\notepad++\notepad++.exe" %* goto :EOF :HELP echo ------------------------------- echo Notepad++ Command Argument Help echo ------------------------------- echo Usage : echo. echo notepad++ [--help] [-multiInst] [-noPlugins] [-lLanguage] [-nLineNumber] [-cColumnNumber] [-xPos] [-yPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [fullFilePathName] echo. echo --help : This help message echo -multiInst : Launch another Notepad++ instance echo -noPlugins : Launch Notepad++ without loading any plugin echo -l : Launch Notepad++ by applying indicated language to the file to open echo -n : Launch Notepad++ by scrolling indicated line on the file to open echo -c : Launch Notepad++ on scrolling indicated column on the file to open echo -x : Launch Notepad++ by indicating its left side position on the screen echo -y : Launch Notepad++ by indicating its top position on the screen echo -nosession : Launch Notepad++ without any session echo -notabbar : Launch Notepad++ without tabbar echo -ro : Launch Notepad++ and make the file to open read only echo -systemtray : Launch Notepad++ directly in system tray echo -loadingTime : Display Notepad++ loading time echo -alwaysOnTop : Make Notepad++ always on top echo fullFilePathName : file name to open (absolute or relative path name) echo. goto :EOF :EOF
You can name it
notepad++.cmd. The help section allows you to easily get information on the switches.
I put all such scripts and command line programs in a directory which is added to
...and that directory is synced to all computers and virtual machines.
Create a batch file with contents like the following:
@"C:\Program Files\Git\bin\git.exe" %*
This should be saved as a
.bat file, such as
git.bat in a directory that's in your
@ suppresses echoing the command to the invoking shell. The quotations
"" prevent white space being interpreted as argument delimiters.
%* pastes any arguments to the batch file, to the quoted executable instead.
You can now invoke the executable using the part of the batch file name before
.bat. In my case,
Drag a shortcut to
Alternatively, as suggested by @Synetech inc., you could place your shortcuts in a separate directory (e.g.
C:\Shortcuts), and then add that directory to
setx PATH "%PATH%;C:\Shortcuts"
As some of the comments indicate, this only works from the Run dialog. In order to get the shortcuts to launch from a command prompt, you need to add the shortcut extension (.LNK) to your PATHEXT environment variable.
setx PATHEXT %pathext%;.LNK
The App Paths registry key does exactly this: set the path to notepad++.exe to "\program files\..." and you'll be able to launch it from Start-Run, cmd, ... just like any executable from a directory in %PATH%.
I didn't like any of the solutions presented here, so I tried something else.
Right-click the file you want to add to your path (in Explorer) and click "Pick Link Source"
Right-click in folder you just created and click
Drop As > Symbolink Link.
Rename the symbolink link if you want.
That's it. You should be able to access your program via the command-line now. If you just added the new folder to your PATH, you will have to restart cmd.exe or Cmder or ConEmu or whatever it is you use. After that, you can add new programs without restarting.