标题: [文本处理] 如果写个BAT批处理修改XML文件内容 [打印本页]
作者: fishhulei 时间: 2019-3-8 09:35 标题: 如果写个BAT批处理修改XML文件内容
大家好,我有个xml文件需要经常修改IP。怎么写个批处理自动修改啊、
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<CenterServerIp>10.32.20.2</CenterServerIp>
<CenterServicePort>XXXXX</CenterServicePort>
<ServicePath>CenterService/SyncUpload</ServicePath>
<UnitSocketPort>XXX</UnitSocketPort>
<UnitCode>320XXXX</UnitCode>
<UnitName>XXXXXXXXX</UnitName>
<NetStateTimer>300000</NetStateTimer>
<UploadTimer>3600000</UploadTimer>
<IsRfid>false</IsRfid>
</configuration>
想把10.32.20.2改成10.32.20.220
作者: ivor 时间: 2019-3-8 10:25
- set oldFile=1.config
- set newFile=2.config
- powershell -command "& {[xml]$configFile= get-content %oldFile%;$configFile.configuration.CenterServerIp='10.32.20.220';$configFile.Save('%newFile%')}"
复制代码
作者: zaqmlp 时间: 2019-3-8 11:44
- @echo off
- title 有什么问题,可加QQ956535081及时沟通;代码可用,扫码头像,随意赞助
- cd /d "%~dp0"
- set "file=test.xml"
- powershell "$Utf8NoBom=New-Object System.Text.UTF8Encoding $False;$t=[IO.File]::ReadAllText('%file%', [Text.Encoding]::UTF8);$t=$t -replace '(?<=<CenterServerIp>)[^<]*','10.32.20.220';[IO.File]::WriteAllText('%file%', $t, $Utf8NoBom);"
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |