Q:

Batch to run exe after checking directory for a file

I have a program that I need to run via command line that I want to make a batch file for to save time. It looks for any files in the same directory with a specific extension and then runs the exe to manipulate the file. Something like:
example.exe option1 *.ext

Where .ext is a file with the correct type of extension it's looking for. The file type usually has different filenames, but always the same extension. The option is just something the program knows how to use so that can be ignored for now.
Trick is I only want this to run IF there isn't already another file in the same directory with the same name but a different extension.
I think I saw something about being able to use IF statements in batch files, but I have no idea how this would be done. Any ideas?

A:

echo off

REM search .txt files.
for %%f in (*.txt) do (
  REM skip if a .log file with the same name exists.
  if not exist %%~nf.log (

    echo Now executing %%f
    notepad.exe %%f
    REM Terminate the loop after the first succesful file
    goto end

  ) else (
    echo Skipping %%f
  )
)

echo Nothing to process.

:end
pause

