Outputs one or more locations of a file or a file name pattern, where the file or pattern does not need to state the extension if it listed in PATHEXT, such as .exe. Searches in the current directory and in the PATH by default. Does some of the job of "which" command of some other operating systems, but is more flexible.
Available on Windows 2003, Windows Vista, Windows 7, and later; not available on Windows XP. An alternative to be used with Windows XP is in the examples below.
Does not find internal commands, as there are no dot exe files for them to match.
Examples:
where find
Outputs the location of the find command, possibly "C:\Windows\System32\find.exe". The .exe extension does not need to be specified as long as it is listed in PATHEXT, which it is by default.
If there are more find commands in the path, outputs paths to both. In some situations, it can output the following:
C:\Windows\System32\find.exeC:\Program Files\GnuWin32\bin\find.exe
for %i in (find.exe) do @echo %~$PATH:i
Outputs the location of "find.exe" on Windows XP. The name has to include ".exe", unlike with the where command.
where /r . Tasks*
Searches for files whose name matches "Task*" recursively from the current folder. Similar to "dir /b /s Tasks*". The /r switch disables search in the folders in PATH.
where *.bat
Outputs all .bat files in the current directory and in the directories that are in PATH. Thus, outputs all .bat files that you can run without entering their full path.
where ls*.bat
As above, constraining also the beginning of the name of the .bat files.
where ls*
As above, but with no constraint on the extension. Finds lsdisks.bat, lsmice.pl, and lsmnts.py if in the current directory or in the path.
where *.exe *.com | more
Displays countless .exe and .com files in the path and in the current folder, including those in C:\Windows\System32.
where $path:*.bat
Outputs .bat files in the path but not those in the current folder unless the current folder is in PATH. Instead of path, another environment variable containing a list of directories can be used.
where $windir:*.exe
Outputs .exe files found in the folder stated in WINDIR environment variable.
where $path:*.bat $windir:*.exe
A combination is possible. Outputs all files matching either of the two queries.
where /q *.bat && echo Found
Suppresses both standard and error output, but sets the error level, enabling testing on it. The error level is set either way, with or without /q.
Links: