The batchcompute (BAT) script can implement the alias function similar to Linux/Unix.

Source: Internet
Author: User

I have previously written a python3 script that can implement the alias function. Later I thought that python is not installed by everyone, and the applicability of the script is limited,

Labels ):

You can put the script in a folder and create a shortcut for open. bat on the desktop,

Click shortcut in the email, select properties, and add the shortcut key for the shortcut: CTRL + ALT + R

In this way, regardless of the window, press CTRL + ALT + R at the same time, and open. Batt will execute.

------------------------------- Readini. Bat ------------------------------------------

Rem @ echo off & setlocal enabledelayedexpansion
Number of REM echo parameters: % 0% 1% 2% 3
Set name1145264 =
Set namelist1145264 =
Set param1145264 =
Set paramlist1145264 =
For/F "EOL =; tokens = 1 * usebackq delims =" % I in (% 1) Do (
Rem echo % I % J
Set P = % I
Rem echo P =! P!
Rem echo character! P! ! P :~ 0, 1! ! P :~ -1! ! P :~ 1,-1!
If "! P :~ 0, 1! "= "["(
If "! P :~ -1! "="] "(
Rem @ echo condition! P :~ 1,-1!
Set name1145264 =! P :~ 1,-1!
Set namelist1145264 =! Namelist1145264 !,! Name1145264!
)
)
Rem echo name1145264 =! Name1145264! Namelist1145264 =! Namelist1145264! Paramlist1145264 =! Paramlist1145264! Enter % 2
If "[! Name1145264!] "NEQ" % I "(
If "! Name1145264! "=" % 2 "(
Set paramlist1145264 =! Paramlist1145264 !, % I
If "% 3" = "% I "(
Set param1145264 = % J
)
)
)
)
Rem echo ------------------------
Rem echo name1145264 =! Name1145264!
Set return =
If "% 2" equ ""(
Rem Name List
Rem echo "! Namelist1145264 :~ 1! "
Set return =! Namelist1145264 :~ 1!
If "! Namelist1145264! "NEQ ""(
Set return =! Namelist1145264 :~ 1!
) Else (
Set return =
)
) Else (
If "% 3" equ ""(
Rem attribute list
Rem echo "! Paramlist1145264! "
If "! Paramlist1145264! "NEQ ""(
Set return =! Paramlist1145264 :~ 1!
) Else (
Set return =
)
) Else (
Rem Attribute Value
Rem echo "! Param1145264! "
Set return =! Param1145264!
If "! Param1145264! "NEQ ""(
Set return =! Param1145264!
) Else (
Set return =
)
)
)
Rem @ echo on

---------------------- Open. Bat --------------------------------------

@ Echo off & setlocal enabledelayedexpansion
Set filename = commandlist. ini
Set myname = 0
: Loop1
Set myname =
Set/P myname = enter the abbreviation:
Rem ECHO: % myname %
If "% myname %" = ""(
Rem echo "the input is empty. Please enter it again"
Goto: loop1
) Else (
If "% myname %" = "help "(
Type help.txt
Echo.
Goto: loop1
)
If "% myname %" = "quit "(
Exit 1
)
If "% myname %" = "show "(
Call readini % filename %
Set P =! Return!
For % I in (! P !) Do (
Call readini % filename % I note
Set P2 = % I
Echo! P2 :~ 0, 15! ! Return!
)
Goto: loop1
)
If "% myname %" = "edit "(
Notepad % filename %
Goto: loop1
)
If "! Myname :~ 0, 2! "=" G "(
Rem echo call! Myname :~ 0, 2! % Filename %! Myname :~ 2!
Call gotopath % filename %! Myname :~ 2!
If! Return! Equ 0 (
Goto loop1
) Else (
Exit
Rem echo ============================ exit ==============================
)
The Echo program cannot run here.
Goto: loop1
)
Call readini % filename % myname % command
Set mycmd =! Return!
Call readini commandlist. ini % myname % Param
Set myparam =! Return!
Call readini commandlist. ini % myname % PATH
Set mypath =! Return!
Call readini commandlist. ini % myname % note
Set mynote =! Return!
If "! Mycmd! "= ""(
ECHO does not find the command for % myname %
Set myname =
Goto: loop1
) Else (
Echo program description :! Mynote!
Set errorlevel =
Rem echo output % errorlevel %
If "! Mypath! "NEQ ""(
Start "open"/D! Mypath! ! Mycmd! ! Myparam!
) Else (
Start "open "! Mycmd! ! Myparam!
)
If % errorlevel % NEQ 0 (
@ Echo error code: % errorlevel %
Goto: loop1
Set myname =
)
Rem @ echo runs successfully
Exit
)
)
@ Echo on
Pause

----------------------------- Gotopath. Bat --------------------------------------

Rem @ echo off & setlocal enabledelayedexpansion
Rem setlocal enabledelayedexpansion
Rem GP: Go to the program directory
Rem echo call readini % 1% 2 path
Set return =
Call readini % 1% 2 path
If "! Return! "NEQ ""(
Start "gotopath" Explorer! Return!
Set return = 1
) Else (
% 2. Path attribute not found in Echo
Set return = 0
)
Result of executing EEE row by rem echo :! Return!
Rem @ echo on

----------------------- Commandlist. ini -------------------------------------

; Testing INI files
Note that the name cannot contain equal signs or spaces.
There cannot be a space between the attribute and the equal sign
[Cmd]
Command=cmd.exe
Param =
Path =
Note = command window
[NP]
Command = notepad
Param =
Path =
Note = notepad
[JS]
Command = "D: \ Program Files \ Kingsoft \ powerword_oxford \ xdict.exe"
Param =
Path =
Note = Kingsoft
[Ed]
Command = "E: \ mydocument \ work learning \ ediary2.53 \ ediary.exe"
Param =
Path =
Note = notepad

---------------------------Help.txt -----------------------------------------

-----------------------------------------
Help documentation
Edit edit configuration file
Help show help document
Quit exits the system
Show show short command list

G is short for the command path, for example: G ues to ue path
Other short commands
-----------------------------------------

========================================================== ====

I hope it will be helpful for everyone's learning and work.

Script Programming, simple, green, non-toxic, happy.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.