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.
Unlike the DIR command WHERE always returns the full path to each file found.
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 specify the .exe extension: 'WHERE.exe' otherwise the Where-Object cmdlet will take precedence.
Find all files named 'Zappa' on the remote computer 'Server64' searching
the subdirectories of Share1:
C:\> WHERE /r \\Server64\Share1 Zappa.*
List all the files in the Demo folder:
C:\> WHERE "C:\demo\:*.*"
List all the .CSV files on both the work and play folders:
C:\> WHERE C:\work\;C:\Play\:*.csv
In PowerShell, find all copies of robocopy.exe in the current system path:
PS C:\> WHERE.exe robocopy.exe
“Who never walks, save where he sees men's tracks, makes no discoveries” ~ Josiah Gilbert Holland
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.
ATTRIB - Display or change file attributes, with just the parameter specifying a file or a wildcard, ATTRIB will return similar results to WHERE.
CD - Change Directory.
DIR - Display a list of files and subfolders.
TYPE - Display the contents of a text file.
Equivalent bash command (Linux): which - Show full path of commands.
Similar PowerShell cmdlet, finds the first copy only: (get-command robocopy.exe).Definition