从Windows批处理文件读入ini
发布时间:2020-12-13 21:04:17 所属栏目:Windows 来源:网络整理
导读:我试图用这种格式读取一个ini文件: [SectionName]total=4[AnotherSectionName]total=7[OtherSectionName]total=12 基本上我想从ini文件中回显出某些值(例如,在OtherSectionName下的总数,后面是来自AnotherSectionName的总数)。 这是一个命令文件(ini.cmd)
我试图用这种格式读取一个ini文件:
[SectionName] total=4 [AnotherSectionName] total=7 [OtherSectionName] total=12 基本上我想从ini文件中回显出某些值(例如,在OtherSectionName下的总数,后面是来自AnotherSectionName的总数)。
这是一个命令文件(ini.cmd),您可以使用它来提取相关值:
@setlocal enableextensions enabledelayedexpansion @echo off set file=%~1 set area=[%~2] set key=%~3 set currarea= for /f "usebackq delims=" %%a in ("!file!") do ( set ln=%%a if "x!ln:~0,1!"=="x[" ( set currarea=!ln! ) else ( for /f "tokens=1,2 delims==" %%b in ("!ln!") do ( set currkey=%%b set currval=%%c if "x!area!"=="x!currarea!" if "x!key!"=="x!currkey!" ( echo !currval! ) ) ) ) endlocal 这是一个抄本显示它在行动(我手动缩进输出,使其更容易阅读): c:src>type ini.ini [SectionName] total=4 [AnotherSectionName] total=7 [OtherSectionName] total=12 c:src>ini.cmd ini.ini SectionName total 4 c:src>ini.cmd ini.ini AnotherSectionName total 7 c:src>ini.cmd ini.ini OtherSectionName total 12 要在另一个cmd文件中实际使用这个,只需将下面的echo%val%行替换成你想要做的任何事情): for /f "delims=" %%a in ('call ini.cmd ini.ini AnotherSectionName total') do ( set val=%%a ) echo %val% (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何在Windows 7 64位上安装ROracle
- windows-phone – 谷歌的新版reCaptcha在Windows Phone上不
- 设计 – 某处有旧版Windows UX指南吗?
- windows – 使用PRTG自动重启服务
- 利用开机账户登录“轻松访问”创建Windows后门
- iis – 经典管道模式下的Windows Identity Foundation(WIF)
- Windows – 如何在域控制器上的本地服务帐户下运行服务
- Windows 10 WMI和事件查看器访问被拒绝
- 下一个Wannacry? Windows为新蠕虫漏洞发布补丁
- 建议在Windows文件夹(NTFS)中有多少个文件?