我有一个属性文件build.properties,其中包含以下信息:
conf.major.number=1
conf.minor.number=0
core.major.number=3
core.minor.number=2
我希望我的批处理脚本从conf.major.number和conf.minor.number中获取值,并将输出结果为1.0并将其设置为变量" version"
当我给出echo%version%时,输出应为1.0
for /f "skip=1 delims== tokens=2" %%a in (build_info.properties) DO (set "version=%%a")
echo %version%
core.major.number=1
core.minor.number=0
以上几行应该被忽略,我不知道如何跳过这些行。
请帮助,
由于
这是解决方案,它完美地感谢@JosefZ
@ECHO OFF SETLOCAL EnableExtensions EnableDelayedExpansion
set VER_FILE="tldconfrev.number"
set /p id=Enter Ant target to be called "revision" or "hi":
set /p flag=Do you want the version file to be updated to perforce (Y/N):
echo(%id%
if /I "%id%"=="revision" (
if /I "%flag%"=="Y" (
for /f "delims=" %%a in (
'type "build_info.properties"^|find "="'
) DO (
set "_%%a"
)
set _
set "version=!_conf.major.number!.!_conf.minor.number!"
echo version=!version!
pause
)
)
答案 0 :(得分:1)
尝试下一步方法:
@ECHO OFF
SETLOCAL EnableExtensions
for /f "delims=" %%a in (
'type "D:\bat\files\build_info.properties"^|find "="'
) DO (
set "_%%a"
)
set _
set "version=%_conf.major.number%.%_conf.minor.number%"
echo version=%version%
<强>输出强>:
==>D:\bat\SO\32266650.bat
_conf.major.number=1
_conf.minor.number=0
_core.major.number=3
_core.minor.number=2
version=1.0
==>
关于您的评论的修改(下一步,edit your question并在那里添加代码):
@ECHO OFF SETLOCAL EnableExtensions EnableDelayedExpansion
set VER_FILE="tldconfrev.number"
set /p id=Enter Ant target to be called "revision" or "hi":
set /p flag=Do you want the version file to be updated to perforce (Y/N):
echo(%id%
if /I "%id%"=="revision" (
if /I "%flag%"=="Y" (
for /f "delims=" %%a in (
'type "build_info.properties"^|find "="'
) DO (
set "_%%a"
)
set _
set "version=!_conf.major.number!.!_conf.minor.number!"
echo version=!version!
pause
)
)
资源(必读):
答案 1 :(得分:0)
不止一种方法可以给猫皮肤涂抹 - 这里还有两种方法:
A:
@echo off
for /f "usebackq delims=" %%a in ("build_info.properties") do set %%a
echo Version is "%conf.major.number%.%conf.minor.number%"
pause
B:
@echo off
<build_info.properties (
set /p maj=
set /p min=
)
set %maj%
set %min%
echo Version is "%conf.major.number%.%conf.minor.number%"
pause