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?

3
  • The comment from @DrMoishePippik is on the money but if you still need help, come back and someone can help you with the if - else logic.. of course batch can do this. Aug 30 '21 at 0:24
  • Yes, also @It Wasn't Me answer! Aug 30 '21 at 5:58
  • 1
    1 minute after @SeñorCMasMas put this comment, I add the answer.. d:)
    – iTwasnTme
    Aug 31 '21 at 5:00
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 /?
1
  • Much obliged, simple and does the trick. Aug 30 '21 at 5:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.