用于读取.ini文件的Windows批处理脚本
发布时间:2020-12-13 20:48:31 所属栏目: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% (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- active-directory – 从2008迁移到2012R2域后无法看到AD
- Windows – 学习MFC编程的先决条件
- windows-phone – Windows Phone 8上的FontAwesome
- 使用fopen增加Windows中Matlab中打开文件描述符的最大数量
- windows-xp – Linux“traceroute -A”(AS路径查找)等效于W
- 如何在Windows中设置和使用Jpegtran
- Windows – 如何将多个文件名传递给上下文菜单Shell命令?
- Windows – Visual Studio 2010 – 如何减少其内存占用
- Windows应用程序数据目录
- windows-7 – 使用SYSTEM帐户运行SEP扫描
推荐文章
站长推荐
- windows – 如何将我的OpenGL应用程序置于全屏模
- 单点登录 – ADFS被动请求=“没有注册协议处理程
- 使用Windows DHCP / DHCPv6服务器而不设置静态地
- xaml – 按钮样式看起来像应用程序栏按钮
- Windows-8 – 用HTML / CSS / JS编写的Metro应用
- xaml – WinRT&Light主题
- WPF:用WindowState最大化窗口问题(应用程序将隐
- Windows和Native API中的系统调用?
- windows server 2003&nbs
- [Windows 8] Windows 8.1预览版下载及实装试用
热点阅读