标题: [求助]关于chenall的《批处理读取INI文件》
[打印本页]
作者: laoxiao
时间: 2008-10-5 16:48
标题: [求助]关于chenall的《批处理读取INI文件》
作者: HAT
时间: 2008-10-5 17:14
修改echo语句
@echo off
:::::::::INI文件读取 by chenall QQ:366840202::::::::::::::::::::::
::使用方法: ::
:: inifile iniFilePath ::
::例子: ::
:: inifile c:\boot.ini ::
:: 读取c:\boot.ini的所有 ::
:: inifile c:\boot.ini "" ::
:: 读取c:\boot.ini 段的内容 ::
:: inifile c:\boot.ini "" timeout ::
:: 显示c:\boot.ini 段 timeout的值 ::
::07-04-26 新增设置变量的功能,只需将下面的setvar=0改为1即可 ::
::::::::::::::::::::::::::::::::::::::::::::2006-12-21::::::::::::
set setvar=0
::当有指定参娄并且setvar值为1时就将的值设为变量
::例子inifile c:\boot.ini "" timeout 就可以得到一个%timeout%的变量
set item=
set filepath=
set section=
if not "%~1"=="" (
set filepath=%1
) else goto :file_err
if not exist %filepath% goto :file_err
setlocal EnableDelayedExpansion
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!
)
endlocal&set "item=%item%"&set "section=%section%"
for /f "usebackq delims= skip=2" %%i in (`find /i "%section%" /n %filepath%`) do set 字段开始=%%i
if "%字段开始%"=="" goto :eof
for /f "eol=; usebackq tokens=1* skip=%字段开始% delims==" %%i in (`type %filepath%`) do (
set a=%%i
setlocal EnableDelayedExpansion
if "!a:~0,1!"=="
作者: laoxiao
时间: 2008-10-6 23:00
感谢 HAT 版主!
但是在我这里并没有把显示在 cmd 窗口里面的 ini 文件的内容复制到 b.ini 文件,即使已经设置 setvar=1。
作者: HAT
时间: 2008-10-7 01:44
标题: Re 3楼
你的使用方法不对吧?
Microsoft Windows XP
(C) Copyright 1985-2001 Microsoft Corp.
C:\Test>inifile c:\boot.ini ""
C:\Test>type b.ini
timeout=5
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS