Windows Vista e versioni successive vengono forniti con un programma chiamato where.exe
che ricerca i programmi nel percorso. Funziona in questo modo:
D:\>where notepad
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
D:\>where where
C:\Windows\System32\where.exe
Per l'utilizzo in un file batch è possibile utilizzare l'interruttore /q
, che ha appena imposta ERRORLEVEL
e non produce alcun output.
where /q myapplication
IF ERRORLEVEL 1 (
ECHO The application is missing. Ensure it is installed and placed in your PATH.
EXIT /B
) ELSE (
ECHO Application exists. Let's go!
)
o una versione semplice (ma meno leggibile) stenografia che stampa il messaggio ed esce la vostra applicazione:
where /q myapplication || ECHO Cound not find app. && EXIT /B
fonte
2014-09-06 03:08:45
possibile duplicato di [Come verificare se un file esiste nel batch DOS] (http://stackoverflow.com/questions/4340350/how-to-check-if-a-file-exists-in-dos-batch) – karlphillip
@karlphilip: Sicuramente no. La domanda qui è abbastanza diversa. – Joey
Devi contrassegnare una risposta accettata. – Jeb