Skip to content

Instantly share code, notes, and snippets.

@Bigous
Created November 9, 2015 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bigous/84dac1e905447724dd10 to your computer and use it in GitHub Desktop.
Save Bigous/84dac1e905447724dd10 to your computer and use it in GitHub Desktop.
Finds where is an executable in the path.
@echo off
setlocal
set FOUNDFLAG=0
:# Adiciona o diretório corrente no path para esta pesquisa apenas.
set PATH=%PATH%;.
if exist "%~$PATH:1" ( echo Encontrado em %~$PATH:1 && set FOUNDFLAG=1)
:# Precisamos pesquisar o executável com todas as extensões de execução disponíveis.
:# Substitui . por espaço.
set SPEC=%PATHEXT:.= %
:# Remove os ;.
set SPEC=%SPEC:;=%
:# Itera sobre todas as extensões de execução disponíveis.
for %%a in (%SPEC%) do call :CHECK %1.%%a
goto :CLEANUP
:CHECK
if exist "%~$PATH:1" ( echo Encontrado em %~$PATH:1 && set FOUNDFLAG=1 )
goto :EOF
:CLEANUP
if not %FOUNDFLAG% == 1 echo Nenhum executável encontrado: %1
endlocal
goto :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment