JSI Tip 8474. InPath.bat locates a file in your path.


In tip 7585, Whence.bat script locates specified files in a path, I presented a complex script with a number of configurable options.

I have scripted InPath.bat to simply return the fully qualified file name of the first occurence of the specified file in your path.

The syntax for using InPath.bat is:

InPath FileName.ext

where FileName.ext is a file name with extension.

Examples

InPath notepad.exe
displays
C:\WINDOWS\SYSTEM32\notepad.exe

InPath notepad
displays nothing.

InPath abcd.efg
displays nothing.

InPath regedit.exe
displays
C:\WINDOWS\regedit.exe

To use the ouput of InPath.bat in your script:

set FQFN=None
for /f "Tokens=*" %%a in ('InPath FileName.ext') do (
 set FQFN=%%a
)
NOTE: If FQFN EQU "None", the file was not found in your path.

InPath.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: InPath FileName.ext&goto :EOF
for /f "Tokens=*" %%F in ('@echo %1') do (
 If "%%~dp$PATH:F" NEQ "" @echo %%~dp$PATH:F%%~F
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish