本文介绍了批处理脚本来更新属性文件中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于该批次的问题。

I have a question regarding the batch.

我有一个性质目录中的文件。其中有一个文本BuildNumber = 0。我想用BuildNumber =%BUILD_NUMBER%来代替这个BuildNumber = 0。我使用下面的脚本来实现这一点。

I have a properties file in Directory. Which has a text "BuildNumber=0". I want to replace this "BuildNumber=0" with "BuildNumber=%BUILD_NUMBER%". I am using the following script to achieve this

@echo on
setlocal enabledelayedexpansion enableextensions


ATTRIB -r -s C:\bldarea\myfile\..\..\jenkinstest\abc.properties

CD C:\bldarea\myfile\file\Main_Releases\jenkinstest\
call :FindReplace "Buildnumber=0" "Buildnumber=%BUILD_NUMBER%" abc.properties
exit /b

:FindReplace <Buildnumber=0> <Buildnumber=%BUILD_NUMBER%> <abc.properties>
set tmp="%temp%\tmp.txt"
If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
<%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
)
)
del %temp%\_.vbs
exit /b

:MakeReplace
>%temp%\_.vbs echo with Wscript
>>%temp%\_.vbs echo set args=.arguments
>>%temp%\_.vbs echo .StdOut.Write _
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\_.vbs echo end with

这个脚本的问题是,它不转换BuildNumber = 0到目前的版本号。

The problem with this script is , It is not converting BuildNumber=0 to current Build Number.

在code线:

:FindReplace <Buildnumber=0> <Buildnumber=%BUILD_NUMBER%> <abc.properties>

如果我删除%符号那么它打印BuildNumber =%BUILD_NUMBER%,但BuildNumber = 0仍然是present在doc。是否有人可以帮助我正确地替换文本。

if I remove % symbol then it is printing the "BuildNumber=%BUILD_NUMBER%" but the "BuildNumber=0" is still present in the doc. Can someone please help me out to replace the text correctly.

感谢。

推荐答案

只需插入双百分比在这一行:

Just insert double percents in this line:

call :FindReplace "Buildnumber=0" "Buildnumber=%BUILD_NUMBER%" abc.properties

是这样的:

call :FindReplace "Buildnumber=0" "Buildnumber=%%BUILD_NUMBER%%" abc.properties

这篇关于批处理脚本来更新属性文件中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 19:24