bat 读配置文件 *.properties
bat 读配置文件 *.properties
圣洁之子 发表于2年前
bat 读配置文件 *.properties
  • 发表于 2年前
  • 阅读 27
  • 收藏 0
  • 点赞 0
  • 评论 0

移动开发云端新模式探索实践 >>>   

I want to read a property file like below and get the particular key value 

My properties file looks like    

I want to get the version from the properties file. You can do this by various methods. 

Using Type function: 

C:\Users\Chenjo\Desktop>type | find "version"

There is a disadvantage with this method you could not store that value in a variable. 

Using For Loop: 

C:\Users\Chenjo\Desktop>FOR /F %i IN ( DO echo %i 

Using this command you can read that file line by line. 

FOR /F "eol=; tokens=2,2 delims==" %i IN ( DO echo %i 

Using this commend you can get the values only. 

eol is End of Line 

tokens is specifying which tokens are displayed – 2,2 means only the second token will be displayed 

delims is the deliminator. This is the separator 

FOR /F "eol=; tokens=2,2 delims==" %i IN ('findstr /i "version"') DO set version=%i   

Using findstr we get the correct string from the properties file and give as an input to the for loop. 

That for loop processes the result and set that value to the variable version. 

findstr /i means it is not a case sensitive one. 

Using echo you can get the value. 

echo %version% 

When using it in a bat, add a % befor %i. That is like 

FOR /F "eol=; tokens=2,2 delims==" %%i IN ('findstr /i "version"') DO set version=%%i    
echo %version%   


  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 6
博文 228
码字总数 91273
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
* 支付类型