Aliases in Windows command prompt

后端 未结 16 2776
故里飘歌
故里飘歌 2020-11-22 10:47

I have added notepad++.exe to my Path in Environment variables.

Now in command prompt, notepad++.exe filename.txt opens the filename

16条回答
  •  庸人自扰
    2020-11-22 11:40

    If you're just going for some simple commands, you could follow these steps:

    1. Create a folder called C:\Aliases
    2. Add C:\Aliases to your path (so any files in it will be found every time)
    3. Create a .bat file in C:\Aliases for each of the aliases you want

    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.

提交回复
热议问题