替换 .bat 文件中的文本

发布于 2025-01-06 02:31:18 字数 873 浏览 2 评论 0原文

我在名为 C:\durvi\mmi_test\mmidurvi 的文件夹中有 2 个文件夹,它们是 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..  
)  

提前感谢您的帮助!

I have 2 folders in folder called C:\durvi\mmi_test\mmidurvi which are
C:\durvi\mmi_test\mmidurvi\durvyauu
C:\durvi\mmi_test\mmidurvi\sgdf
Both these folders have Connections.xml file
I would like to replace any occurance of ql99015 with dd32261
A sample format of file is as below

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

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

I tried something like below but does not work:

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

Thanks for your help in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装纯掩盖桑 2025-01-13 02:31:18

将脚本更改为:

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

Change the script to:

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"
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文