Posted By

maphew on 04/17/09


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


look for given .exe in PATH

 / Published in: DOS Batch


I'm always forgetting the syntax for this, and finding it is hard because the key words apply to so many different uses that aren't this one

  1. @echo off
  2. for %%f in (foobar.exe) do (
  3. if exist "%%~dp$PATH:f" echo %%f located at "%%~dp$PATH:f"
  4. )

Report this snippet  


RSS Icon Subscribe to comments
Posted By: Vordreller on April 17, 2009

Sorry dude, syntax is wrong, copied it, made it one line, replaced foobar.exe with notepad.exe, entered it, got an error message:

%%f was unexpected at this time.

Posted By: maphew on April 21, 2009

use double percent (%%f) when in batch file, single (%f) when a command line. So for command line use it would be:

for %f in (notepad.exe) do if exist "%~dp$PATH:f" echo %f located at "%~dp$PATH:f"

You need to login to post a comment.