批处理脚本以搜索和查找文件,然后替换字符串

时间:2019-06-13 13:20:49

标签: batch-file

尝试创建一个批处理脚本,该脚本可以在每个用户的配置文件中找到该文件,然后替换该文件中的某个字符串。该文件的位置是:C:\Users\%username%\AppData\Roaming\Sage Software\Sage MAS 500\application.config

我让后一部分工作,但不确定如何找到文件。

@echo off
setlocal enabledelayedextensions

set "search= ^<ReportPath^>C:\Program Files ^(x86^)\Sage Software\Sage MAS 500 Client^</ReportPath^>"
set "replace=^<ReportPath^>\\bcshare.belterracorp.com\masreports^</ReportPath^>"

set "textFile=application.config"

for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    >>"%textFile%" echo(!line:%search%=%replace%!
    endlocal
)

0 个答案:

没有答案
相关问题