0

I have either 01.png, 01.jpg or 01.webp and the file.bat in the same folder.

based on these .ext I want to execute a command in .bat

if 01.png exist then
    do something
or if 01.jpg exist then
    do something
or if 01.webp exist then
    do something

Is this possible with BATCH or even .cmd?

1 Answers1

4

You can try if() else if() else if ()...

@echo off

cd /d "%~dp0"

if exist 01.png ( command ) else if exist 01.jpg ( command ) else if exist 01.webp ( command )


If you need, you can add an else to handle the nonexistence of your files...

@echo off

cd /d "%~dp0"

if exist 01.png ( command ) else if exist 01.jpg ( command ) else if exist 01.webp ( command ) else echo file not exist

  • Some further reading: If /?
Io-oI
  • 9,237