使用批处理脚本将float变量的值增加1 [英] Increasing value of float variable by 1 using batch script

查看:634
本文介绍了使用批处理脚本将float变量的值增加1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次运行批处理脚本时,都需要增加float变量versionName的值. 就像2.5到2.6,2.7一样.

I need increase float variable versionName value every time I run batch script. Like 2.5 to 2.6 ,2.7 so on.

这是我的文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.sisapp.in.globalthesc" android:versionName="2.5" android:versionCode="8">
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28" />
    <supports-screens android:resizeable="true"  android:largeScreens="true"/>
    <application android:icon="@drawable/sisIconLaunch">        
        <receiver android:name=".DeviceBootReceiver" />
    </application>
</manifest>

我正在尝试如下操作,但无法正常工作

I am trying like below but it is not working

@echo off
set "inputfile=D:\raja\SIS\SIS_Product\edTheSIS\AppIcons\Global\MenifestFile\AndroidManifest.xml
set /A versionName=%versionName%+1

推荐答案

好吧,所以我首先要说批处理不是操作xml文件的最佳工具,有些工具比批处理要好得多

Ok, so let me start of by saying that batch is not the best tool to manipulate xml files, there are tools that can do much better than batch.

还请注意,此脚本纯属黑客行为,如果您发布的xml文件格式(尤其是清单标记行)发生变化,则它将无法正常工作,并且 Will 中断文件.因此,在开始备份xml文件之前.

Note also that this script is purely a hack, if the format of your xml file changes (especially the manifest tag line) from what you have posted, then it will not work and it WILL break your file. So before you start make a backup of your xml file.

此外,它会显式替换找到的数字值,如果该值在文件中的其他任何位置也将替换它.

Also, this explicitely replaces the numeric value it finds, if the value exists anywhere else in the file, it will also replace it.

最后也是非常重要的一点,如果您的xml文件由任何!字符组成,则将无法满足此要求,并且将从替换中排除.

Lastly and very importantly, if your xml file consists of any ! characters, this will not cater for it and it will be excluded from the replace.

@echo off
setlocal enabledelayedexpansion
set "inputfile=D:\raja\SIS\SIS_Product\edTheSIS\AppIcons\Global\MenifestFile\AndroidManifest.xml"

    for /f tokens^=8^delims^=^" %%i in ('type "%inputfile%" ^| findstr "android:versionName"') do set vers=%%i
    for /f "tokens=1,2 delims=." %%i in ("!vers!") do (
         set decia=%%i
         set decib=%%j
         if "!decib!" lss "9" (
                set /a decib+=1
          ) else (
                set decib=0
                set /a decia+=1
        )
        set newver=!decia!.!decib!
    )
    for /f "tokens=*" %%a in ('type "%inputfile%" ^| find /v /n "" ^& break ^> "%inputfile%"') do (
         set "str=%%a"
         call set "str=%%str:*]=%%"
         if "!str:~0,15!" == "<manifest xmlns" set "str=!str:%vers%=%newver%!"
         >>%inputfile% echo(!str!
  )

这篇关于使用批处理脚本将float变量的值增加1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆