替换.bat文件中的文本

时间:2012-02-15 17:25:15

标签: batch-file dos

我在文件夹中有2个名为C:\ durvi \ mmi_test \ mmidurvi的文件夹 C:\ durvi \ mmi_test \ mmidurvi \ durvyauu C:\ durvi \ mmi_test \ mmidurvi \ sgdf
这两个文件夹都有Connections.xml文件
我想用dd32261替换ql99015的任何出现 文件的样本格式如下

<pre><anyType xsi:type="xsd:string">ql99015</anyType>  

<anyType xsi:type="xsd:string">ql99015_flowreeng_Anthony</anyType>  </pre>

我尝试了类似下面的内容但不起作用:

for /D %%f in (c:\durvi\mmi_test\mmidurvi\*) do (  
cd %%f  
if not exist "Connections.xml" (echo this file does not exist)&goto :eof  
SETLOCAL=ENABLEDELAYEDEXPANSION  
ren "Connections.xml" "Connections1.xml"  
for /f %%a in (Connections1.xml) do (    
set write=%%a  
echo %%a   
if !write!=="ql99015" set write="dd32261"  
echo !write! >> Connections.xml  
)  
del "Connections1.xml"  
cd..  
)  

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

将脚本更改为:

SETLOCAL ENABLEDELAYEDEXPANSION
for /r %%a in (connections.xml) do (
  move "%%a" "%%a.temp"
  for /f "usebackq tokens=*" %%b in ("%%a.temp") do (
    set write=%%b
    echo !write:ql99015=dd32261! >> "%%a"
  )
  del "%%a.temp"
)