Board logo

标题: [文本处理] 批处理如何修改ini文件的指定值 [打印本页]

作者: yym黄诗瑶    时间: 2017-9-28 14:39     标题: 批处理如何修改ini文件的指定值

  1. @echo off & setlocal enabledelayedexpansion
  2. set ListenPort=0
  3. set IsSupport=0
  4. goto dealmanager1  
  5. set EableCall=1
  6. set EableOneMoreCall=1
  7. set Eable60P=0
  8. goto dealmanager2
  9. set Conference_Module=Meeting
  10. goto dealmanager3
  11. :dealmanager1
  12. (for /f " delims=:" %%h in ('findstr /n "." "!SourcePath!\Config\CoreDefConfig.ini"') do (
  13.     set "str=%%i"
  14.     if "!str:ListenPort=!" neq "%%i" (
  15.         echo ListenPort=!ListenPort!
  16.     ) else if "!str:IsSupport=!" neq "%%i" (
  17.         echo IsSupport=!IsSupport!
  18.     ) else (
  19.         echo,%%i
  20.     )
  21. ))>"!SourcePath!\Config\2.ini"
  22. del "!SourcePath!\Config\CoreDefConfig.ini"
  23. rename "!SourcePath!\Config\2.ini" "CoreDefConfig.ini"
  24. :dealmanager2
  25. (for /f "tokens=1* delims=:" %%h in ('findstr /n "." "!SourcePath!\Config\I7DefConfig.ini"') do (
  26.     set "str=%%i"
  27.     if "!str:EableCall=!" neq "%%i" (
  28.         echo EableCall=!EableCall!
  29.     ) else if "!str:EableOneMoreCall=!" neq "%%i" (
  30.         echo EableOneMoreCall=!EableOneMoreCall!
  31.     )  else if "!str:Eable60P=!" neq "%%i" (
  32.         echo Eable60P=!Eable60P!
  33.     ) else (
  34.         echo,%%i
  35.     )
  36. ))>"!SourcePath!\Config\3.ini"
  37. del "!SourcePath!\Config\I7DefConfig.ini"
  38. rename "!SourcePath!\Config\3.ini" "I7DefConfig.ini"
  39. :dealmanager3
  40. (for /f "tokens=1* delims=:" %%h in ('findstr /n "." "!SourcePath!\Module.ini"') do (
  41.     set "str=%%i"
  42.     if "!str:Conference_Module=!" neq "%%i" (
  43.         echo Conference_Module=!Conference_Module!
  44.     ) else (
  45.         echo,%%i
  46.     )
  47. ))>"!SourcePath!\4.ini"
  48. del "!SourcePath!\Module.ini"
  49. rename "!SourcePath!\4.ini" "Module.ini"
  50. pause
复制代码
替换文本内容,只有第一个dealmanager1修改成功,第二个dealmanager2修改失败,等号后面没有值,为空。第三个deal也有问题,很奇怪。
作者: 见与不见    时间: 2017-10-14 00:33

帖子沉了,居然没有人回帖
作者: 老刘1号    时间: 2017-10-14 12:10

本帖最后由 老刘1号 于 2017-10-14 12:12 编辑

批处理修改INI文件函数块+用法+实例




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2