bat解析ini文件
1 @echo off 2 setlocal enabledelayedexpansion 3 4 set INIFILE=%1 5 6 rem -------------------------- 7 rem ini内容解析 8 rem -------------------------- 9 for /f "delims=" %%i in (%INIFILE%) do ( 10 set rowStr=%%i 11 12 rem -------------------------- 13 rem [User*]解析 14 rem -------------------------- 15 if "!rowStr:~0,5!" EQU "[User" ( 16 rem UserNo取得 17 set currentUserNo=!rowStr:~5,-1! 18 19 rem UserNo设定 20 set User!currentUserNo!=!rowStr! 21 22 rem UserName index设定 23 set currentUserName=UserName!currentUserNo! 24 25 rem PassWord index设定 26 set currentPassWord=PassWord!currentUserNo! 27 ) 28 29 rem -------------------------- 30 rem UserName解析 31 rem -------------------------- 32 if "!rowStr:~0,9!" EQU "UserName=" ( 33 rem UserName值取得 34 set rowStr=!rowStr:~9%! 35 36 rem UserName设定 37 set !currentUserName!=!rowStr! 38 ) 39 40 rem -------------------------- 41 rem PassWord解析 42 rem -------------------------- 43 if "!rowStr:~0,9!" EQU "PassWord=" ( 44 rem PassWord值取得 45 set rowStr=!rowStr:~9%! 46 47 rem PassWord设定 48 set !currentPassWord!=!rowStr! 49 ) 50 ) 51 52 pause 53 endlocal 54 exit /b
INI文件:
[User61]
UserName=wang123
PassWord=sfsfs
[User2]
UserName=chao456
PassWord=fghhg
[User34]
UserName=guo789
PassWord=yuiyuiy