I want to make a batch file that detects if a file named lang-XX.txt exist in a directory, the XX will be a language code like EN (english), FR (france), etc.
However, I do not want to make it using multiple if exist lang-XX.txt
command like:
if exist lang-US.txt goto launchGame
if exist lang-FR.txt goto launchGame
if exist lang-DE.txt goto launchGame
if exist lang-IT.txt goto launchGame
if exist lang-JP.txt goto launchGame
if exist lang-PL.txt goto launchGame
if exist lang-RU.txt goto launchGame
if exist lang-ES.txt goto launchGame
rem This will set game language and launch the game on the 'launchGame' section
So, I want to make it like:
set "lang=US=FR=DE=IT=JP=PL=RU=ES"
if exist lang-%lang%.txt goto launchGame
But of course, it will not work since there are multiple lang
variable and typing echo %lang%
will result US=FR=DE=IT=JP=PL=RU=ES
. So, how do I make it works?
Here are my current full batch file:
@echo off
title Saints Row IV Launcher
:checkLang
set "lang=US=FR=DE=IT=JP=PL=RU=ES"
if exist lang-%lang%.txt goto launchGame
:startMenu
echo/
echo This is a launcher + language changer for Saints Row IV.
echo Your selected language will be saved to "lang-XX.txt" file.
echo/
echo This launcher will read from it so you don't need to change the
echo language again every time you launch the game using this launcher.
echo Please make sure that you have write access to this directory!
echo/
echo Avaiable languages:
echo 1) English
echo 2) French
echo 3) German
echo 4) Italian
echo 5) Japanese
echo 6) Polish
echo 7) Russian
echo 8) Spanish
echo/
set "lang="
set /P "menu=Please type the number correctly: "
if not defined %lang% goto checkLang
if "%menu%"=="1" set lang=US
if "%menu%"=="2" set lang=FR
if "%menu%"=="3" set lang=DE
if "%menu%"=="4" set lang=IT
if "%menu%"=="5" set lang=JP
if "%menu%"=="6" set lang=PL
if "%menu%"=="7" set lang=RU
if "%menu%"=="8" set lang=ES
:launchGame
rem Will detect if 'lang-XX.txt' file existed, if not, make a new 'lang-XX.txt' file
if not exist lang-%lang%.txt type nul >lang-%lang%.txt
rem Start the game with %lang% parameter...
start "" "Saints Row IV.exe" -localize_language %lang%
And if possible, if multiple lang-XX.txt file existed on one directory (example: lang-EN.txt and lang-JP.txt), how do I make the batch file to show an error or goto XXXXX
instead of continuing the process?