坛子以前有篇帖子介绍批处理读文件
http://www.cn-dos.net/forum/viewthread.php?tid=25789&sid=PMXBgq
功能已经很完善,我现在想把结果写进一个变量比如result
再循环内部用
set result = %%x
循环外部用echo %result%显示不出结果
总说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的值 ::
:: ::
::::::::::::::::::::::::::::::::::::::::::::2006-12-21::::::::::::
set result=
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!
)
setlocal disableDelayedExpansion
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
call :trim a
if "!a:~0,1!"=="
%%x&endlocal
)
endlocal
)
)
endlocal
endlocal
)
endlocal
goto :eof
:section
endlocal
for /f "eol=; usebackq delims== skip=2" %%i in (`find /i "
http://www.cn-dos.net/forum/viewthread.php?tid=25789&sid=PMXBgq
功能已经很完善,我现在想把结果写进一个变量比如result
再循环内部用
set result = %%x
循环外部用echo %result%显示不出结果
总说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的值 ::
:: ::
::::::::::::::::::::::::::::::::::::::::::::2006-12-21::::::::::::
set result=
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!
)
setlocal disableDelayedExpansion
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
call :trim a
if "!a:~0,1!"=="
%%x&endlocal
)
endlocal
)
)
endlocal
endlocal
)
endlocal
goto :eof
:section
endlocal
for /f "eol=; usebackq delims== skip=2" %%i in (`find /i "
