标题: [文本处理] [已解决]BAT怎么修改ini文件中某行中指定字符? [打印本页]
作者: 无敌大怪兽 时间: 2020-2-10 11:23 标题: [已解决]BAT怎么修改ini文件中某行中指定字符?
举例 配置.ini中的内容如下 (省略号表示其他行的内容)
[Launcher]
CommandLine = -connect=192.168.200.1 -port=80 -name=wuwu
...
...
...
...
Lanport = 80
就是把CommandLine行中-port=后面的端口号替换成指定的内容行中其他的不变,比如改成5555。
[Launcher]
CommandLine = -connect=192.168.200.1 -port=5555 -name=wuwu
...
...
...
...
Lanport = 80
这里的端口号是不固定可能是任意数值,不管-port=后面是啥都直接替换。
作者: zaqmlp 时间: 2020-2-10 20:37
- @echo off
- set info=互助互利,支付宝扫码头像,感谢打赏
- rem 有问题,可加QQ956535081及时沟通
- title %info%
- cd /d "%~dp0"
- set "inifile=配置.ini"
- set newport=5555
- powershell -NoProfile -ExecutionPolicy bypass ^
- $enc=[Text.Encoding]::Default;^
- $text=[IO.File]::ReadAllText('%inifile%', $enc);^
- $text=$text -replace '(?^<=CommandLine.+?-port=)\d+','%newport%';^
- [IO.File]::WriteAllText('%inifile%', $text, $enc);
- :end
- echo;%info%
- pause
- exit
复制代码
作者: 无敌大怪兽 时间: 2020-2-10 22:03
回复 2# zaqmlp
测试通过,膜拜大佬。太感谢了
作者: zaqmlp 时间: 2020-2-10 22:12
回复 3# 无敌大怪兽
那就赞助下吧
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |