All pastes #366782 Raw Edit

Untitled

public text v1 · immutable
#366782 ·published 2007-02-21 22:27 UTC
rendered paste body
@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set result=
set found=
if exist "%~1"  call :abspath "%~1"
if not "%found%" == "" goto :end
call :checkpath "%~1"
if not "%found%" == "" goto :end
set i=1
:checkexts
set ext=
for /F "usebackq tokens=%i% eol=;" %%x in (`echo %PATHEXT%`) do (
	set ext=%%~x
	if exist "%~1%%~x" (
		set found=1
		set result=%~1%%~x
		goto :end
	) else (
		call :checkpath "%~1%%~x"
	)
)
if "%ext%" == "" goto :end
if not "%found%" == "" goto :end
set /A i+=1
goto :checkexts
:end
call :abspath "%result%"
if "%found%" == "1" (
	echo %result%
) else (
	echo File not found.
)
ENDLOCAL
goto :eof

:checkpath
set result=%~$path:1
if exist "%result%" call :abspath %result%
goto :eof

:abspath
set result=%~f1
set attribs=%~a1
if "%result%" == "" (
	goto :eof
) else if "%attribs%" == "" (
	call :abspath %result%
	goto :eof
)
if not "%attribs:~0,1%" == "d" if exist "%result%" set found=1
goto :eof