使用 bat 脚本 修改yml文件

1.将文件中的xxxxxx替换为当前路径,并保留yml格式(空格,换行)

最好去掉yml中的注释,不然可能出问题

下面的:PATH方法好像没用

@echo off
rem CMD:"color --help"
:: setting color:back white,content blue
color f9

::old string and replace string
set old_str=xxxxxx
set new_str=%cd%

:FILE
set "souerce_path=%cd%\apache-tomcat-8-readerAndSolr\webapps\yoyue\WEB-INF\classes\application-prod.yml"
for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%souerce_path%"') do (
    set "lineContent=%%j"
    ::echo ==%%j==
    setlocal EnableDelayedExpansion
    if not "!lineContent!"=="" set "lineContent=!lineContent:%old_str%=%new_str%!"
    >>"temp.txt" echo.!lineContent!
    endlocal
)
move /y temp.txt "%souerce_path%"
goto END

:PATH
::files path
set "souerce_path=%cd%\b.bat"
cd /d "%souerce_path%"

:: dir /s /b /a-d *.txt  ::get all current and sub path file name with post .txt
for /f "delims="  %%a in ('dir /s /b /a-d *.txt') do (
    for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%%a"') do (
        set "lineContent=%%j"
        ::echo ==%%j==
        ::here use "setlocal EnableDelayedExpansion" to keep content "!"
        setlocal EnableDelayedExpansion
        if not "!lineContent!"=="" set "lineContent=!lineContent:%old_str%=%new_str%!"
        >>"%%~dpnxas" echo.!lineContent!
        endlocal
    )
    del /s /q /f "%%a" >nul
    ren *.txts *.txt
)
:END
echo   ---------updateYml complete----------

2.修改properties也是一样
set "souerce_path=%cd%\epub.properties"

set old_str=\
set new_str=/

for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%souerce_path%"') do (
    set "lineContent=%%j"
    ::echo ==%%j==
    setlocal EnableDelayedExpansion
    if not "!lineContent!"=="" set "lineContent=!lineContent:%old_str%=%new_str%!"
    >>"temp.txt" echo.!lineContent!
    endlocal
)

move /y temp.txt "%souerce_path%"
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值