I have added notepad++.exe
to my Path in Environment variables.
Now in command prompt, notepad++.exe filename.txt
opens the filename
Also, you can create an alias.cmd in your path (for example C:\Windows) with the command
@echo %2 %3 %4 %5 %6 > %windir%\%1.cmd
Once you do that, you can do something like this:
alias nameOfYourAlias commands to run
And after that you can type in comman line
nameOfYourAlias
this will execute
commands to run
BUT the best way for me is just adding the path of a programm.
setx PATH "%PATH%;%ProgramFiles%\Sublime Text 3" /M
And now I run sublime as
subl index.html
If you're just going for some simple commands, you could follow these steps:
Maybe overkill, but unlike the (otherwise excellent) answer from @Argyll, this solves the problem of this loading every time.
For instance, I have a file called dig2.bat with the following in it:
@echo off
echo.
dig +noall +answer %1
Your np file would just have the following:
@echo off
echo.
notepad++.exe %1
Then just add the C:\Aliases folder to your PATH environment variable. If you have CMD or PowerShell already opened you will need to restart it.
FWIW, I have about 20 aliases (separate .bat files) in my C:\Aliases directory - I just create new ones as necessary. Maybe not the neatest, but it works fine.
UPDATE: Per an excellent suggestion from user @Mav, it's even better to use %* rather than %1, so you can pass multiple files to the command, e.g.:
@echo off
echo.
notepad++.exe %*
That way, you could do this:
np c:\temp\abc.txt c:\temp\def.txt c:\temp\ghi.txt
and it will open all 3 files.
Using doskey is the right way to do this, but it resets when the Command Prompt window is closed. You need to add that line to something like .bashrc equivalent. So I did the following:
Works just fine!
Actually, I'll go you one better and let you in on a little technique that I've used since I used to program on an Amiga. On any new system you use, be it personal or professional, step one is to create two folders: C:\BIN
and C:\BATCH
. Then modify your path statement to put both at the start in the order C:\BATCH;C:\BIN;[rest of path]
.
Having done that, if you have little out-of-the-way utilities that you need access to simply copy them to the C:\BIN
folder and they're in your path. To temporarily override these assignments, you can add a batch file with the same name as the executable to the C:\BATCH
folder and the path will find it before the file in C:\BIN. It should cover anything you might ever need to do.
Of course, these days the canonical correct way to do this would be to create a symbolic junction to the file, but the same principle applies. There is a little extra added bonus as well. If you want to put something in the system that conflicts with something already in the path, putting it in the C:\BIN
or C:\Batch
folder will simply pre-empt the original - allowing you to override stuff either temporarily or permanently, or rename things to names you're more comfortable with - without actually altering the original.