我有一个包含以下内容的xml文件:
<setParameter value="\\deveserver\d$\Websites\anime" name="IIS Web Application Name"/>
我想编写一个批处理脚本,它将搜索这个\\deveserver\d$\Websites\anime字符串(保存在一个名为CurrentFolder的变量中),并用输入的任何内容替换它。
我将输入的路径保存在变量DestinationFolder中
SET DestinationFldr=
SET /p DestinationFldr=Enter Destination path:我检查的任何替换和文本帖子似乎都不起作用。我认为它无法识别双反斜杠。请帮帮忙。谢谢。
发布于 2013-04-16 00:15:35
@ECHO off
SETLOCAL
SET "currentfolder=\\deveserver\d$\Websites\anime"
SET "DestinationFldr=some\variety\of\input"
(
FOR /f "delims=" %%i IN ('type aninput.xml^|findstr /n /r "$" ') DO (
SET line=%%i
SETLOCAL ENABLEDELAYEDEXPANSION
SET line=!line:*:=!
IF DEFINED line (ECHO(!line:%currentfolder%=%destinationfldr%!) ELSE (ECHO()
endlocal
)
)>anoutput.xml
FC aninput.xml anoutput.xml将currentfolder设置为指定的值,将destfldr设置为某个字符串以模拟输入,
%%i中,并用前导number :对其进行编号-包括空行line部分(即,仍定义由<代码>D18插入的行号,<代码>D19将其替换为字符串;否则<代码>D20空白行<代码>H221<代码>H122关闭集合本地框架<代码>H223<代码>F224FC inputfile outputfile显示更改
发布于 2013-04-16 00:03:11
如果你在file.xml中有<setParameter value="\\deveserver\d$\Websites\anime" name="IIS Web Application Name"/>,你可以使用下面的代码:
@echo off&setlocal
set "CurrentFolder=\\deveserver\d$\Websites\anime"
for /f "delims=" %%i in (file.xml) do set "html=%%i"
SET DestinationFldr=
SET /p "DestinationFldr=Enter Destination path: "
setlocal enabledelayedexpansion
set "html=!html:%CurrentFolder%=%DestinationFldr%!"
echo html: !html!测试和输出:
Enter Destination path: \\myserver\&&\othersites\adele
html: <setParameter value="\\myserver\&&\othersites\adele" name="IIS Web Application Name"/>https://stackoverflow.com/questions/16019123
复制相似问题