2012-02-15 105 views
1

我在文件夾名爲C 2個文件夾替換文本:\ durvi \ mmi_test \ mmidurvi這是 C:\ durvi \ mmi_test \ mmidurvi \ durvyauu C:\ durvi \ mmi_test \ mmidurvi \ sgdf
這兩個文件夾有Connections.xml文件
我想更換ql99015的任何一次出現與dd32261
文件的採樣格式如下在.bat文件

<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.. 
) 

感謝您的幫助!

回答

2

更改腳本:

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" 
) 
+0

謝謝,我會嘗試這一點,並讓你知道 – NewQueries 2012-02-16 14:27:44

+0

非常感謝它完美:),我只是說,我一直在尋找connections.xml「的路徑/ R c:\ durvi \ mmi_test \ mmidurvi \ * %% a(connections.xml)do(' – NewQueries 2012-02-16 15:05:00