Created
November 9, 2015 16:40
-
-
Save Bigous/84dac1e905447724dd10 to your computer and use it in GitHub Desktop.
Finds where is an executable in the path.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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