使用批处理修改.properties文件中的字符串 [英] Modify a string in a .properties file with batch
本文介绍了使用批处理修改.properties文件中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过执行脚本来修改csm.properties中的某个属性. 我仔细检查了一下,最后找到了这段代码.
I am trying to modify a certain property in my csm.properties by executing a script. I looked up a lot and in the end, came to this code.
set "search=CLASSPATH"
set "insert=CLASSPATH^=plugins^/Numbering.jar^\^:"
set "textFile="%workingPlace%bin\csm.properties""
FOR /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
FOR /f "tokens=1*delims==" %%g IN ("%%i") DO (
IF /i "%%g" == %search% (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%textFile%" echo(!line:%search%=%insert%!
endlocal
)ELSE (
%%i
)
)
)
此代码应读取文件中的每一行,并使用=
作为分隔符.如果代码将"CLASSPATH"作为属性,则应修改该行.
但似乎找不到CLASSPATH.
This code should read every line in my file and use =
as a delimiter. If the code gets "CLASSPATH" as property, that line should get modified.
But it seems like CLASSPATH isn't found.
csm.properties的外观如下:
This is how csm.properties looks like:
#Tue Jul 10 08:50:23 CEST 2018
JAVA_ARGS=-Xmx20000M -DLOCALCONFIG\=true -splash\:data/splash.png -Dmd.class.path\=$java.class.path -Dcom.nomagic.osgi.config.dir\=configuration -Desi.system.config\=data/application.conf -Dlogback.configurationFile\=data/logback.xml -Dsun.locale.formatasdefault\=true -Dinitial.user.language\=de
JAVA_HOME=jre1.8.0_152
BOOT_CLASSPATH=lib/xalan.jar
MAIN_CLASS=com.nomagic.osgi.launcher.ProductionFrameworkLauncher
MAC_JAVA_ARGS="-Xdock\:name\=Cameo Systems Modeler" -Xdock\:icon\=bin/md.icns -Dapple.laf.useScreenMenuBar\=true
APP_ARGS=
DEFAULT_MEMORY_SETTINGS_64=-Xmx[30%,1200,4000]M
DEFAULT_MEMORY_SETTINGS_32=-Xmx800M
CLASSPATH=lib/patch.jar\:lib/brand_api.jar
CONSOLE=false
修改后,CLASSPATH
应如下所示:
CLASSPATH=plugins/Numbering.jar\:lib/patch.jar\:lib/brand_api.jar
推荐答案
简单...
@echo OFF
setlocal
set "search=CLASSPATH"
set "insert=plugins/Numbering.jar\:"
set "textFile=%workingPlace%bin\csm.properties"
(FOR /f "usebackq tokens=1* delims==" %%i in ("%textFile%") do (
if "%%i" equ "%search%" (
echo %search%=%insert%%%j
) else if "%%j" neq "" (
echo %%i=%%j
) else (
echo %%i
)
)) > temp.tmp
move /Y temp.tmp "%textFile%"
这篇关于使用批处理修改.properties文件中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文