Board logo

标题: 怎么更改ini文件里的内容? [打印本页]

作者: terrytong     时间: 2008-4-29 17:17    标题: 怎么更改ini文件里的内容?

我们配置文件里有这么一段:
[SFCS]
        Testserver = TSTUSI09
        station1 = B4
        station2 = B6
        user = m009986
        shift = 1
        opid = FNCT
        PROTOCOL= AutoIFICS
现在我想编一个P,我运行一下,红色内容会变成PROTOCOL= NOIFICS
再运行一下,它又变回原来的PROTOCOL= AutoIFICS.
简单的说就是让它切换。
我以前用VB可以实现的,现在喜欢上p了,哪位高手帮帮我啊。
作者: huahua0919     时间: 2008-4-29 19:24
用注册表构建临时文件应该可行
作者: terse     时间: 2008-4-29 19:53
@echo off                                 
for /f "delims=" %%i in (1.ini) do set str=%%i&call:lp
pause
goto :eof
:lp
if "%str:~0,1%"==" " set str=%str:~1%&goto lp
if "PROTOCOL= AutoIFICS"=="%str%" echo.PROTOCOL= NOIFICS>>1.ini&goto :eof
if "PROTOCOL= NOIFICS"=="%str%" echo.PROTOCOL= AutoIFICS>>1.ini&goto :eof
if not defined a (echo.%str% >1.ini&set a=ok) else echo.%str% >>1.ini
作者: knoppix7     时间: 2008-4-29 20:15
http://home.mnet-online.de/horst.muc/wbat32.htm#inifile
似乎这个程序可以.
作者: xvzheng     时间: 2008-4-29 23:28
文件INI主要是做什么的。
作者: HAT     时间: 2008-4-30 00:26
来个不用for循环的
@echo off
findstr "AutoIFICS" a.txt>nul
>a.txt (
    echo [SFCS]
    echo         Testserver = TSTUSI09
    echo         station1 = B4
    echo         station2 = B6
    echo         user = m009986
    echo         shift = 1
    echo         opid = FNCT
    echo         opid = FNCT
)
if %errorlevel% equ 0 (
  >>a.txt echo         PROTOCOL= NOIFICS
) else (
  >>a.txt echo         PROTOCOL= AutoIFICS
)
[ Last edited by HAT on 2008-4-30 at 12:28 AM ]
作者: terrytong     时间: 2008-4-30 12:44
谢谢HAT的答案,你的可以实现我要的功能。
如果我的INI文件还有很多其它字符,需要更改的都是PROTOCOL= AutoIFICS,那这个方法就不是很好了。
如果我有很多这样的文件,内容也不是一样的,还是要改PROTOCOL= AutoIFICS,这个办法也不是很好。
所以如果能有直接对该INI文件操作的就好了。不管什么文件有多少字符,不管多少个文件,我直接找到PROTOCOL= AutoIFICS,然后更改,再写回去,这样行的通吗?
作者: HAT     时间: 2008-4-30 15:15
change.exe可以在本版下载到
@echo off
findstr "AutoIFICS" *.ini>nul
if %errorlevel% equ 0 (
  change *.ini /from AutoIFICS /to NOIFICS /in PROTOCOL
) else (
  change *.ini /from NOIFICS /to AutoIFICS /in PROTOCOL
)