A 90-byte “whereis” program – The Old New Thing
Posted by jpluimers on 2018/11/23
I needed a “get only the first result” of WHERE
(which is present after Windows 2000, so XP, Server 2003 and up), so based on [WayBack] A 90-byte “whereis” program – The Old New Thing I came up with this:
@echo off :: based on https://blogs.msdn.microsoft.com/oldnewthing/20050120-00/?p=36653 ::for %%f in (%1) do @echo.%%~$PATH:f for %%e in (%PATHEXT%) do @for %%i in (%1 %~n1%%e) do ( @if NOT "%%~$PATH:i"=="" ( echo %%~$PATH:i goto :eof ) ) :: note: WHERE lists all occurrences of a file on the PATH in PATH order goto :eof
Two changes:
- it takes into account the extension if you specify it (unlike WHERE.EXE)
- it bails out at the first match (like WHERE.EXE)
References:
- [WayBack] Where – locate files – Windows CMD – SS64.com
- [WayBack] Is there an equivalent of ‘which’ on the Windows command line? – Stack Overflow
–jeroen
Leave a Reply