Search files from the Windows Command Prompt with dir, where and findstr

How to Search for Files From the Windows Command Prompt (dir, where, findstr)

The File Explorer search box is fine until it is slow, or until you are on a server with no desktop, or you need a result you can paste into a script. Windows has three built-in tools for finding files from the command line: dir finds files by name, where finds them by name and can show their size and date, and findstr finds files by what is written inside them. I ran every command below on Windows 11 Pro against a small test folder, so the outputs are real.

The test folder

The examples use this layout:

C:\demo
  todo.txt
  Reports\
    budget-notes.txt
    2026\
      budget-q3.xlsx

Find files by name with dir

Go to the folder you want to search and use dir with /s (look in subfolders) and /b (print only the full path, no headers):

cd /d C:\demo
dir /s /b *budget*
C:\demo\Reports\budget-notes.txt
C:\demo\Reports\2026\budget-q3.xlsx

The pattern matches both files and folders whose names fit. Add /a-d to leave folders out, or /ad to list only folders:

dir /s /b /ad
C:\demo\Reports
C:\demo\Reports\2026

Find files with where

where is best known for locating programs on your PATH, but with /r it searches a folder recursively, starting wherever you point it:

where /r C:\demo *budget*
C:\demo\Reports\budget-notes.txt
C:\demo\Reports\2026\budget-q3.xlsx

Add /t to see each file’s size, date and time. The columns are size in bytes, last-modified date, time and path:

where /r C:\demo /t *.txt
         3   15-10-2026      23:11:19  C:\demo\todo.txt
         3   15-10-2026      23:11:19  C:\demo\Reports\budget-notes.txt

The date format follows your regional settings. Run where /? to see all options, including /q, a quiet mode that only sets the exit code, which is handy in batch files.

Find files by their contents with findstr

To search inside files, use findstr. These switches cover most needs: /s searches subfolders, /i ignores case, and /m prints only the names of files that contain a match instead of every matching line:

cd /d C:\demo
findstr /s /i /m "x" *.txt
Reports\budget-notes.txt
todo.txt

Drop /m and findstr prints each matching line together with its file name. Add /n to include line numbers. Searching inside files such as .xlsx or .docx will not work well, because they are compressed containers rather than plain text.

Searching a whole drive

You can run dir /s /b C:\*budget* from any folder, but expect it to take a while on a large drive and to skip folders you are not allowed to read. Redirect the output to a file when the list is long, and choose a name that does not match your search and a folder you can write to:

dir /s /b C:\*budget* > "%USERPROFILE%\found-files.txt"

A single > overwrites the file if it already exists; use >> to append instead.

The PowerShell equivalent

If you are already in PowerShell, Get-ChildItem does the same job and returns objects you can sort and filter:

Get-ChildItem C:\demo -Recurse -File -Filter *budget* | Select-Object FullName, Length, LastWriteTime

Common questions

Why does dir show nothing for a file I know exists?

Check that you used /s, otherwise it only looks in the current folder. Then check the pattern. * stands for any run of characters and ? for a single character, and Windows also compares against the old 8.3 short file names, which can make results surprising. Spell out what you want: use *.doc* to cover both .doc and .docx.

Can these tools search hidden files?

dir skips hidden and system files unless you ask for them with /a, for example dir /s /b /a. Some folders also need administrator rights to read.

Is there a size or date filter?

Not in dir. Use where /t to see sizes and dates, or PowerShell’s Where-Object for conditions such as “larger than 100 MB”.

Sources

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *