WHERE.exe

Locate and display files in a directory tree.

The WHERE command is roughly equivalent to the UNIX 'which' command. By default, the search is done in the current directory and in the PATH.

Syntax
      WHERE [/R Dir] [/Q] [/F] [/T] Pattern ...

      WHERE [/Q] [/F] [/T] [Path;Path;... :]Pattern ...

      In PowerShell:
      C:\Windows\System32\WHERE.exe ..options as above

key
   /R      A recursive search, starting with the specified Dir directory.

   /Q      Don’t display the files but return either an exit code of 0 for success
           or 1 for failure.

   /F      Display the output file name in quotation marks.

   /T      Display the size, time stamp, and date stamp of the file.

  pattern  The Drive\Directory\file, or set of files to be found.
           you can use wildcard characters ( ? * ) and UNC paths.

           The pattern can also be $ENV:Pattern where ENV is an existing environment variable
           containing one or more paths.

  Path     One or more semicolon-separated paths to search. 

The WHERE command can either perform a recursive search within one directory (/R) or search through a list of folders (Path;Path:), but not both.

By default, WHERE searches the current directory and the paths specified in the PATH environment variable.

The WHERE command is particularly useful to reveal multiple versions of the same comand/script/utility on the system PATH.

WHERE will use the PATHEXT variable to include all executable files, so WHERE robocopy will find the location of robocopy.exe

This PATHEXT expansion applies even if you are not searching for an executable. For instance, the command WHERE monday.csv will list the file monday.csv in the current directory, as expected, but this will also list files like monday.csv.exe, monday.csv.com should they exist. To avoid this behaviour, clear the PATHEXT variable temporarily with Set "PATHEXT="

To run the WHERE command from PowerShell it is necessary to give the full path C:\Windows\System32\WHERE.exe otherwise the Where-Object cmdlet will take precedence.

Examples

Find all copies of robocopy.exe in the current system path:

C:\Windows\System32\WHERE robocopy.exe

Find all files named 'Zappa' on the remote computer 'Server64' searching the subdirectories of Share1:

WHERE /r \\Server64\Share1 Zappa.*

List all the .CSV files on both the work and play folders:

WHERE C:\work\;C:\Play\:*.csv

“Who never walks, save where he sees men's tracks, makes no discoveries” ~ Josiah Gilbert Holland

Related:

Which.cmd - Show full path to executable.
OldNewthing - Describes this 90 byte 'whereis' batch file:
@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i
whereis utility - Flounder.com.
Which - several scripts from Rob Vanderwoude.
CD - Change Directory.
TYPE - Display the contents of a text file.
Equivalent bash command (Linux): which - Show full path of commands.
Equivalent PowerShell cmdlet: (get-command $file).Definition


 
Copyright © 1999-2020 SS64.com
Some rights reserved