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