[批处理]ini文件读取

本文介绍了一个使用批处理脚本来解析配置文件的方法。该脚本能够处理文件路径、配置节和具体配置项,并能准确地从指定配置文件中读取所需信息。适用于需要批量处理配置文件的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@echo off set item= set filepath= set section= setlocal EnableDelayedExpansion if not "%~1"=="" ( set filepath=%1 ) else goto :file_err if not exist %filepath% goto :file_err if not "%~2"=="" ( set section=%2 if "!section:~0,1!"==""^" set section=!section:~1! if "!section:~-1!"==""^" set section=!section:~0,-1! ) else goto :section if not "%~3"=="" ( set item=%3 if "!item:~0,1!"==""^" set item=!item:~1! if "!item:~-1!"==""^" set item=!item:~0,-1! ) setlocal disableDelayedExpansion set 字段开始= for /f "usebackq delims=[]" %%i in (`find /i "%section%" /n %filepath%`) do set 字段开始=%%i for /f "usebackq tokens=1* delims== skip=%字段开始%" %%i in (`type %filepath%`) do ( set a=%%i setlocal EnableDelayedExpansion if "!a:~0,1!"=="[" goto :eof if not "!a:~0,1!"==";" ( setlocal disableDelayedExpansion for /f "delims=;" %%x in ("%%i=%%j") do ( if not DEFINED item (echo %%x) else (if /i "%%i"=="%item%" echo %%x) ) ) ) goto :eof :section setlocal disableDelayedExpansion for /f "usebackq delims== skip=2" %%i in (`find /i "[" %filepath%`) do echo %%i goto :eof :file_err setlocal disableDelayedExpansion echo. echo %1文件未找到或未输入! echo. goto :eof
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值