我根据其他一些示例编写了此代码,但是无法使其正常工作? (这是一个.bat文件)?该代码将所有旧行写入新文件,只是不会使用“ =”字符来编辑三行。有人可以指出我正确的方向。
这是INTOUCH.INI文件看起来像的样子:
Product productSample = new ProductSample();
1) //productSample setters for few fields
2) new ObjectMapper().readValue(jsonSample, product);
3//productSample setters for few fields
这是写的:
[InTouch]
AppMode=2
AppName0=test
AppName1=
AppName2=
AppName3=
AppDesc0=New InTouch application
AppDesc1=
AppDesc2=
AppDesc3=
SAOConverted=1
WinFullScreen=1
WinLeft=-4
WinTop=-4
WinWidth=1032
WinHeight=748
UseNewSendKeys=1
DebugScripts=0
UseBigBitmap=1
WindowViewerStartupIconic=0
CloseOnTransfer=0
这是我的.bat文件代码:
[InTouch]
AppMode=2
AppName0=test
AppName1=
AppName2=
AppName3=
AppDesc0=New InTouch application
AppDesc1=
AppDesc2=
AppDesc3=
SAOConverted=1
1=WinFullScreen=0=1
WinLeft=-4
WinTop=-4
1032=WinWidth=1000=1032
748=WinHeight=700=748
UseNewSendKeys=1
DebugScripts=0
UseBigBitmap=1
WindowViewerStartupIconic=0
CloseOnTransfer=0
答案 0 :(得分:1)
如果您使用文件格式有好处,则可以在脚本顶部设置新变量的值,然后在从设置文件中读取变量名时,可以查看这些变量是否已定义。如果已定义,则输出新值,否则输出原始值。
诀窍是同时使用CALL
和ECHO
命令时获得双变量扩展。首先,将for变量扩展为变量名,然后在扩展的第二阶段中,扩展变量的值。这就是额外的百分比符号集的原因。
@echo off
Set "WinFullScreen=0"
Set "WinWidth=1000"
Set "WinHeight=700"
REM cd /d F:\
for %%F in (INTOUCH.INI) do set "outFile=%%~nF_edited%%~xF"
REM Read first line of file
set /p line1=<INTOUCH.INI
(echo %line1%
for /f "usebackq skip=1 tokens=1,2 delims==" %%G in ("INTOUCH.INI") do (
if defined %%G (
CALL echo %%G=%%%%G%%
) else (
echo %%G=%%H
)
))>"%outFile%"
Exit /b
答案 1 :(得分:0)
@echo off
Set "AppMode=x"
Set "WinFullScreen=0"
Set "WinWidth=1000"
Set "WinHeight=700"
for /f "skip=1 usebackq tokens=1,2 delims==" %%G in ("a.INI") do call :proc "%%G" %%H
exit /b
:proc
set val=%2
for /F "tokens=* eol= " %%S in ("%~1") do set trimmed=%%S
call :getoverrideval %trimmed%
if "%override%" == "" (
echo %~1=%2%
) else (
echo %~1=%override%
)
goto :EOF
:getoverrideval
call set override=%%%1%%
输出:
C:\Users\w16coreeval>cmd /c a.bat
AppMode=x
AppName0=test
AppName1=
AppName2=
AppName3=
AppDesc0=New
AppDesc1=
AppDesc2=
AppDesc3=
SAOConverted=1
WinFullScreen=0
WinLeft=-4
WinTop=-4
WinWidth=1000
WinHeight=700
UseNewSendKeys=1
DebugScripts=0
UseBigBitmap=1
WindowViewerStartupIconic=0
CloseOnTransfer=0