can I use CMD to search for files in windows?

I want a command to search for a file in a directory and all sub directories in windows using the command line. I saw all the available commands but I couldn't find any suitable command to do this operation.

3 Answers

At prompt (Command Line) type:

dir /S /P "Path\FileName"

If you want to save the results in a text file:

dir /S "Path\FileName" > "Path\ResultFilename"
3

use the /b switch to dir to print full path might be helpful. say, C:\ > dir /b /s *file*.*

still, you can filter the result with find or for, and redirect output to file with >filename

dir was not meant for searching files but to list directories, but now there is where which can be used to search multiple file types as where /R c:\Users *.dll *.exe *.jpg

do check the full syntax and the answer for How to do a simple file search in cmd

WHERE [/R dir] [/Q] [/F] [/T] pattern...
Description: Displays the location of files that match the search pattern. By default, the search is done along the current directory and in the paths specified by the PATH environment variable.
Parameter List: /R Recursively searches and displays the files that match the given pattern starting from the specified directory. /Q Returns only the exit code, without displaying the list of matched files. (Quiet mode) /F Displays the matched filename in double quotes. /T Displays the file size, last modified date and time for all matched files. pattern Specifies the search pattern for the files to match. Wildcards * and ? can be used in the pattern. The "$env:pattern" and "path:pattern" formats can also be specified, where "env" is an environment variable and the search is done in the specified paths of the "env" environment variable. These formats should not be used with /R. The search is also done by appending the extensions of the PATHEXT variable to the pattern. /? Displays this help message. NOTE: The tool returns an error level of 0 if the search is successful, of 1 if the search is unsuccessful and of 2 for failures or errors.
Examples: WHERE /? WHERE myfilename1 myfile????.* WHERE $windir:*.* WHERE /R c:\windows *.exe *.dll *.bat WHERE /Q ??.??? WHERE "c:\windows;c:\windows\system32:*.dll" WHERE /F /T *.dll 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like