[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 如果写个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

  1. set oldFile=1.config
  2. set newFile=2.config
  3. powershell -command "& {[xml]$configFile= get-content %oldFile%;$configFile.configuration.CenterServerIp='10.32.20.220';$configFile.Save('%newFile%')}"
复制代码
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

  1. @echo off
  2. title 有什么问题,可加QQ956535081及时沟通;代码可用,扫码头像,随意赞助
  3. cd /d "%~dp0"
  4. set "file=test.xml"
  5. 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);"
  6. pause
复制代码
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

返回列表