If you know the path where you'd expect to find the EXE, it's fairly easy:
IF EXIST C:\Windows\wget.exe ( *** do something with it ***)
...of course you could do IF NOT EXIST
with a blurb to copy it, or use an ELSE
statement.
Otherwise, if you don't know where you might find the file, you can search for it with something like this (original source found here):
@echo off
SETLOCAL
(set WF=)
(set TARGET=wget.exe)
:: Look for file in the current directory
for %%a in ("" %PATHEXT:;= %) do (
if not defined WF if exist "%TARGET%%%~a" set WF=%CD%\%TARGET%%%~a)
:: Look for file in the PATH
for %%a in ("" %PATHEXT:;= %) do (
if not defined WF for %%g in ("%TARGET%%%~a") do (
if exist "%%~$PATH:g" set WF=%%~$PATH:g))
:: Results
if defined WF (
*** do something with it here ***
) else (
echo The file: "%~1" was not found
)
You could wrap that whole block into a function and call it once for each EXE (change the %TARGET%
s back into %~1
, give it a :TITLE, then call :TITLE wget.exe
)...
Alternately, you could take a different approach and just try the commands and see if they fail. Since ERRORLEVEL of 0 usually means success, you could do something like this:
wget -q <TARGET_URL>
IF NOT ERRORLEVEL 0 (
curl <TARGET_URL>
IF NOT ERRORLEVEL 0 (
ECHO Download failed!
EXIT 1
)
)
:: now continue on with your script...