Batch read ini configuration file

Source: Internet
Author: User
Tags echo name

The batch processing function is very powerful. Below I wrote a script that can read the ini configuration file.

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

Rem @ echo off & setlocal enabledelayedexpansion
Number of REM echo parameters: % 0% 1% 2% 3
Set Name =
Set namelist =
Set Param =
Set paramlist =
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 Name =! P :~ 1,-1!
)
)
Rem echo name =! Name! Namelist =! Namelist! Paramlist =! Paramlist! Enter % 2
If "" = "% 2 "(
Rem echo namelist =! Namelist! % I
If! Namelist! Equ ""(
If "! P :~ 1,-1! "NEQ ""(
Rem echo Step 1! Namelist!
Set namelist =! P :~ 1,-1!
)
) Else (
If "! P :~ 1,-1! "NEQ ""(
Rem echo Step 2 UUUU! Namelist! UUUU
Set namelist =! Namelist !,! P :~ 1,-1!
)
)
) Else if "! Name! "=" % 2 "(
If "% 3" = ""(
If "[! Name!] "NEQ" % I "(
If "! Paramlist! "= ""(
Set paramlist = % I
) Else (
Set paramlist =! Paramlist !, % I
Rem echo returns the property % I % J.
)
)
) Else (
If "% I" = "% 3 "(
Set Param = % J
)
)
)
)
Rem echo ------------------------
Rem echo name =! Name!
If "% 2" equ ""(
Rem Name List
Echo "! Namelist :~ 1! "
) Else (
If "% 3" equ ""(
Rem attribute list
Echo "! Paramlist! "
) Else (
Rem Attribute Value
Echo "! Param! "
)
)
Rem @ echo on

Bytes ----------------------------------------------------------------------------------------

------------------------------- 1. ini ---------------------------------------------

; INI file for testing
Note that the name cannot contain equal signs or spaces.
There cannot be a space between the attribute and the equal sign
[ABC]
Cd = OOP
Me = KKE = d F
[BBB]
Cd = WSD
Me =
----------------------------------------------------------------------------------

------------------- Call method test. Bat ----------------------------------------

@ Echo off & setlocal enabledelayedexpansion
Echo ---- readini 1. ini ----
Call readini 1.ini
Echo ---- readini 1.ini ABC ----
Call readini 1.ini ABC
Echo ---- readini 1.ini ABC me ----
Call readini 1.ini ABC me
@ Echo on
Pause

Bytes -----------------------------------------------------------------------------------
Running Effect

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.