3

Possible Duplicate:
Running programs by typing some alias in Windows

Right now I have Notepad++ (or any other app) in my PATH and can fire it up from the CMD by typing notepad++ < filename > - which is fine. But I'd like to use it like npp < filename > as it's faster and less typing.

Can this be done?

unicorn_crack
  • 143
  • 1
  • 3

5 Answers5

7

One solution is to create in the notepad++ directory (or anywhere else in the path) a file called npp.bat that contains the following line :

@echo off
"C:\Program Files\Notepad++\notepad++.exe" %*

change the above directory, if notepad++ is installed in another directory.

To launch notepad++ without cmd waiting :

@echo off
start "" "C:\Program Files\Notepad++\notepad++.exe" %*
harrymc
  • 455,459
  • 31
  • 526
  • 924
  • You'll keep the CMD prompt hung that way. – paradroid Jan 31 '11 at 13:10
  • @paradroid: To launch notepad++ without cmd waiting can also be done : `start "" "C:\Program Files\Notepad++\notepad++.exe" "%1"` – harrymc Jan 31 '11 at 13:19
  • @harrymc: I know, I said that in my answer, and it is better to use `"%~1"` as the parameter, as that will strip any quotes from a filename that uses them. – paradroid Jan 31 '11 at 13:20
  • 1
    It's even better to use `%*` (unquoted), to pass unmodified _all_ arguments given to the batch file. – u1686_grawity Jan 31 '11 at 13:25
  • @grawity: Yeah, usually, but Notepad++ has its switches before the filename. – paradroid Jan 31 '11 at 13:26
  • @paradroid: What does that change? You can still use `"....\notepad++.exe" /foo /bar %*` or `npp.cmd /foo file.txt` (whichever you meant). – u1686_grawity Jan 31 '11 at 13:29
  • @grawity: I guess I did not realise that as it passes them unmodified that the quote stripping would be unnecessary. See here: http://superuser.com/questions/228592/adding-an-exe-to-default-path-without-adding-the-directory – paradroid Jan 31 '11 at 13:35
  • @grawity: You are right about the %*, answer modified. – harrymc Jan 31 '11 at 13:40
  • Thank you guys for your responses, this indeed works great! – unicorn_crack Jan 31 '11 at 19:26
4

One last idea:

The "doskey" utility, available at the NT command line, provides a facility called "macro", which allows you to specify aliases for the command line without having to change your search path or write a batch file for each EXE file you are interested in. Doskey also provides command-line history for old versions of DOS.

Microsoft provides doskey, so you know that it will be on any system you need to use. Doskey has been shipping with Windows (and, before that, MS-DOS) since something like the mid 1990s.

You need to run a command like this once:

doskey /macrofile="c:\somewhere\doskey.macros.txt"

The doskey.macros.txt is a plain text file that has a kind of "alias = command" format, with one alias per line. It looks something like this, with some "unix-like" aliases that I used to use, including the one for npp:

ls = dir $1
mv = move $*
cp = copy $*
cat = type $*
pwd = cd
history = doskey /history
np = "c:\somewhere\notepad++\notepad++.exe" $*
Darin Strait
  • 421
  • 3
  • 4
2

Yes you can. Navigate over to C:\Program Files (x86)\Notepad++\ and copy and paste notepad++.exe into the same directory. Now rename the copy to npp.exe. If the directory is in the PATH, you should be able to use npp as you described.

James T
  • 9,941
  • 4
  • 28
  • 30
1

You can also create a shortcut to the notepad++.exe file, call it (the shortcut) "npp" and put the location of the shortcut onto your path.

This makes a less verbose alternative to the other answer (creating a bat script for each program you want to do this sort of thing with).

TZHX
  • 245
  • 1
  • 6
0

This question again? The same answers were given on a question just a few days ago. I can remember.

But here, mklink, this will make a junction, a symlink:

mklink "C:\Program Files\Notepad++\npp.exe" "C:\Program Files\Notepad++\notepad++.exe"
sinni800
  • 3,150
  • 3
  • 23
  • 36