最近我问了一个关于如何在批处理文件中使用 if-else-Check 的问题,该问题已解决。现在我尝试通过在我的批处理文件中使用多个 if-else-conditions 来扩展它。执行它时,什么也没有发生。
要了解我要完成的工作:我有一个具有 4 种不同状态的 .ini 文件。我希望我的批处理脚本检查每个状态并针对相应的情况执行任务。为了测试,我设置了一个命令来创建一个文件夹,但准备好后它应该执行其他任务。但我认为这对我的问题并不重要。到目前为止,这是我的代码:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=2 delims==" %%G in ('findstr "lang=" conf.ini') do (
if "%%G"=="deu" (
for /f "tokens=2 delims==" %%G in ('findstr "vers=" conf.ini') do (
if "%%G"=="orig" (
for /f "tokens=2 delims==" %%G in ('findstr "enhancements=" conf.ini') do (
if "%%G"=="0" (
for /f "tokens=2 delims==" %%G in ('findstr "modifications=" conf.ini') do (
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOff.modificationsOff
goto :done
)
if "%%G"=="1" (
mkdir DeutscheSprache.Original.EnhancementsOff.modificationsOn
)
goto :done
)
if "%%G"=="1" (
for /f "tokens=2 delims==" %%G in ('findstr "modifications=" conf.ini') do (
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOn.modificationsOff
goto :done
)
if "%%G"=="1" (
mkdir DeutscheSprache.Original.EnhancementsOn.modificationsOn
)
goto :done
)
if "%%G"=="rem" (
for /f "tokens=2 delims==" %%G in ('findstr "enhancements=" conf.ini') do (
if "%%G"=="0" (
for /f "tokens=2 delims==" %%G in ('findstr "modifications=" conf.ini') do (
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOff.modificationsOff
goto :done
)
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOff.modificationsOn
)
goto :done
)
if "%%G"=="1" (
for /f "tokens=2 delims==" %%G in ('findstr "modifications=" conf.ini') do (
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOn.modificationsOff
goto :done
)
if "%%G"=="1" (
mkdir DeutscheSprache.Original.EnhancementsOn.modificationsOn
)
goto :done
)
if "%%G"=="deu" (
for /f "tokens=2 delims==" %%G in ('findstr "vers=" conf.ini') do (
if "%%G"=="orig" (
for /f "tokens=2 delims==" %%G in ('findstr "enhancements=" conf.ini') do (
if "%%G"=="0" (
for /f "tokens=2 delims==" %%G in ('findstr "modifications=" conf.ini') do (
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOff.modificationsOff
)
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOff.modificationsOn
)
goto :done
)
if "%%G"=="1" (
for /f "tokens=2 delims==" %%G in ('findstr "modifications=" conf.ini') do (
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOn.modificationsOff
goto :done
)
if "%%G"=="1" (
mkdir DeutscheSprache.Original.EnhancementsOn.modificationsOn
)
goto :done
)
if "%%G"=="rem" (
for /f "tokens=2 delims==" %%G in ('findstr "enhancements=" conf.ini') do (
if "%%G"=="0" (
for /f "tokens=2 delims==" %%G in ('findstr "modifications=" conf.ini') do (
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOff.modificationsOff
goto :done
)
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOff.modificationsOn
)
goto :done
)
if "%%G"=="1" (
for /f "tokens=2 delims==" %%G in ('findstr "modifications=" conf.ini') do (
if "%%G"=="0" (
mkdir DeutscheSprache.Original.EnhancementsOn.modificationsOff
goto :done
)
if "%%G"=="1" (
mkdir DeutscheSprache.Original.EnhancementsOn.modificationsOn
)
goto :done
)
:done
endlocal
编辑:因为我在评论中被推荐显示我的 conf.ini 文件:
lang=deu
vers=orig
enhancements=0
modifications=0
脚本应该检查所有四个条目并执行彼此不同的任务。出于测试原因,它应该只创建一个文件夹。如果它应该检查语言 (lang) 并继续转到 ger 或 eng。对于这两种情况,它都应该检查版本 (vers)。之后(同样适用于这两种情况)它应该检查增强功能,并且应该对最后一行重复相同的过程。因此我有 16 种可能的结果
编辑2:这些是我期望的结果。为了测试它应该启动一个预定义的浴脚本:
Case 1
lang=ger
vers=orig
enhancements=0
modifications=0
=> Start case1.bat
Case 2
lang=ger
vers=orig
enhancements=0
modifications=1
=> Start case2.bat
Case 3
lang=ger
vers=orig
enhancements=1
modifications=0
=> Start case3.bat
Case 4
lang=ger
vers=orig
enhancements=1
modifications=1
=> Start case4.bat
Case 5
lang=ger
vers=rem
enhancements=0
modifications=0
=> Start case5.bat
Case 6
lang=ger
vers=rem
enhancements=0
modifications=1
=> CStart case6.bat
Case 7
lang=ger
vers=rem
enhancements=1
modifications=0
=> Start case7.bat
Case 8
lang=eng
vers=rem
enhancements=1
modifications=1
=> Start case8.bat
Case 9
lang=eng
vers=orig
enhancements=0
modifications=0
=> Start case9.bat
Case 10
lang=eng
vers=orig
enhancements=0
modifications=1
=> Start case10.bat
Case 11
lang=eng
vers=orig
enhancements=1
modifications=0
=> Start case11.bat
Case 12
lang=eng
vers=orig
enhancements=1
modifications=1
=> Start case12.bat
Case 13
lang=eng
vers=rem
enhancements=0
modifications=0
=> Start case13.bat
Case 14
lang=eng
vers=rem
enhancements=0
modifications=1
=> Start case14.bat
Case 15
lang=eng
vers=rem
enhancements=1
modifications=0
=> Start case15.bat
Case 16
lang=eng
vers=rem
enhancements=1
modifications=1
=> Start case16.bat