配置文件setup.txt 文件内容如下- [Database]
- SQLUserName=SQLUserName
- SQLPassword=SQLPassword
- SQLSource=SQLSource
- OracleUserName=OracleUserName
- OraclePassword=OraclePassword
- OracleSource=OracleSource
复制代码 配置文件所以配置项目内容,可以输入任意的配置项目
需要替换配置文件指定的字符到批处理的变量中- @echo off &setlocal enabledelayedexpansion
- set SQLUserName=ABC
- set SQLPassword=DEF
- set SQLSource=GHI
- set OracleUserName=JKL
- set OraclePassword=MNO
- set OracleSource=PQR
-
- for /f "tokens=*" %%b in (setup.txt) do (
- set bb=%%b
- if exist !bb:~0,11!=="SQLUserName" (
- set SQLUserName=%bb:~13%
- )
- if exist !bb:~0,11!=="SQLPassword" (
- set SQLPassword=%bb:~13%
- )
- if exist !bb:~0,9!=="SQLSource" (
- set SQLSource=%bb:~11%
- )
- if exist !bb:~0,14!=="OracleUserName" (
- set OracleUserName=%bb:~16%
- )
- if exist !bb:~0,14!=="OraclePassword" (
- set OraclePassword=%bb:~16%
- )
- if exist !bb:~0,12!=="OracleSource" (
- set OracleSource=%bb:~14%
- )
- )
-
- echo %SQLUserName%
- echo %SQLPassword%
- echo %SQLSource%
- echo %OracleUserName%
- echo %OraclePassword%
- echo %OracleSource%
-
- pause
复制代码 脚步目的,当配置文件对应的变量名称和批处理对应的变量名称一致,批处理变量取配置文件的值
期望结果
SQLUserName
SQLPassword
SQLSource
OracleUserName
OraclePassword
OracleSource
实际运行结果
CNEX_NEW
CNEX_NEW
e=CNEX_NEW
X_NEW
X_NEW
NEX_NEW
所有判断都取了最后一行的值,刚刚学习批处理希望得到大家的指点。 |