Site Navigation

Aug 25, 2011

Simple Command Line File Search with Windows XP and 7

Microsoft Logo
Ever want to do a really simple file search in Windows? Do you find the Windows graphical search tools difficult to use and unreliable?

Well fear not. You can use the Windows command line and the dir command to do most file searches.

To open a command prompt window:
On Windows XP: Start --> Programs --> Accessories --> Command Prompt
On Windows 7: Start --> All Programs --> Accessories --> Command Prompt

Now you can use the cd command to move around your disk.
To move up 1 directory level: cd ..
To move to the directory root: cd \ or in most cases cd c:\
To move into a directory (to the windows dir from the root directory for example): cd windows

Once you are in the desired directory you are ready to search. Here is a basic example of the command:
dir /s /b myfile.txt

This example would search the current directory and all sub directories for the myfile.txt file. The /s option searches subdirectories. The /b option displays the path to the file so you can see the path to the file and use a tool like File Manager to navigate to it.

Here are a couple more examples.

Here is an example of a search for all files that end in .help.txt. The * means all files with this file extension. This search takes place in the c:\windows directory.

C:\WINDOWS>dir /s /b *.help.txt

Here is an example of a search for all files that contain winhelp in the file name with any extension.

C:\WINDOWS>dir /s /b winhelp.*


As long as you do not search the entire disk, performance is really quite snappy. Even searching the entire disk is still pretty good.


dave randolph said...

One thing I've noticed under Windows 7 is that the pattern *.tmp will actually translate to *.tmp* and pick up files like xyz.tmp12

do you happen to know if this behavior can be changed?

MikeW said...

Short answer. No. I can't seem to find a solution. This only seems to happen if the extension is 3 or more characters. If I have XML files and search for *.xm, there are no matches. However, if I search for HTML files with .htm, I get both .htm and .html files.

It is either a bug or a feature. My guess is Microsoft would say its a feature. :)

Favorite Links Feed