nested IF statements, best practice (newbie question)
Posted: 08 Jun 2023 17:57
Hello everyone,
I have occasionally stumbled upon this forum, there is lots of brilliance here. I am not very skillful with batch, but I have some coding experience in other languages.
I have a very basic question today - it's about best practice, professionalism, practicality.
Here is a snippet of code from my script, this section of code checks for some required .dll files that an .exe will need. These checks occur before attempting to run the .exe, because if they're not detected, you get a nasty "loud" popup message outside of cmd.
This is just some testing, for example all of the echoed messages are for troubleshooting. To me, this seems very "primitive", I am wondering if there is any better way to write this? I have made an attempt to code something using "nested" if statements, it looks much nicer, and allows any reader of the script to immediately see that these EXIST checks are related to each other, however it doesn't work at all. Here is my attempt:
So the question is: is it worth trying to make this 2nd method work, can it work? If it can, where did I go wrong? I apologise in advance as this is probably very basic question, unfortunately I could not find many good examples of nested IF statements like this...
I have occasionally stumbled upon this forum, there is lots of brilliance here. I am not very skillful with batch, but I have some coding experience in other languages.
I have a very basic question today - it's about best practice, professionalism, practicality.
Here is a snippet of code from my script, this section of code checks for some required .dll files that an .exe will need. These checks occur before attempting to run the .exe, because if they're not detected, you get a nasty "loud" popup message outside of cmd.
Code: Select all
IF EXIST libiconv2.dll (
set 3_DEP=y
echo libiconv2.dll exists
) else (
set error=6
goto errorexit
)
IF EXIST libintl3.dll (
set 4_DEP=y
echo libintl3.dll exists
) else (
set error=7
goto errorexit
)
IF EXIST libcharset1.dll (
set 5_DEP=y
echo libcharset1 exists
) else (
set 5_DEP=n
echo optional dependency libcharset1.dll missing
Code: Select all
IF EXIST libiconv2.dll (
set 3_DEP=y
echo libiconv2.dll exists
IF EXIST libintl3.dll (
set 4_DEP=y
echo libintl3.dll exists
IF EXIST libcharset1.dll (
set 5_DEP=y
echo libcharset1 exists
) else (
set 5_DEP=n
echo optional dependency libcharset1.dll missing
) else (
set error=7
goto errorexit
) else (
set error=6
goto errorexit
)