The default Windows 7 search feature is a major pain. Especially if you’re trying to find a specific value inside a file and the file is not a regular text file, such as .php or .java files, or any other extension for that matter. Luckily there is an alternative way and without the need to install any 3rd party software.

With the powerful FINDSTR command you can perform complex searches for content that is inside any file, any extension. The /R argument allows you to specify Regular Expressions. Use /I for case-insensitive searches and /S to search through sub-directories.

First you need to open up a Command Prompt. You can either type cmd in the search box in the menu from the Start button, or click Start -> All Programs -> Accessories -> Command Prompt.

In the Command Prompt, use the CD command to browse to the directory in which you wish to search. For instance:
cd \temp\wordpress

Finally run the FINDSTR command. For instance to search for the WP_TEMP_DIR string inside all .php files:
findstr /i /s /n wp_temp_dir *.php

You can close the Command Prompt either by mouse, just like any other window, or by executing the exit command in the Command Prompt.

A note about ascii (text) files vs binary files.

Files such as .css, .js, .jsp, .php, .java, .bat, .csv, etc. are usually plain text files, just with a different extension due to the purpose of such files. You could open all those files in a simple text editor such as notepad and see their exact contents.

However, most other file types, such as .doc, .docx, .xls, etc are binary files. If you were to open such files in notepad, you would see weird characters and nonsense that only makes sense to the Word program, or the Excel program, etc.

Even though technically you could use FINDSTR to search inside binary files such as Word documents, you may not find the text you’re looking for, even if that text does indeed exist in the document once you open it in Word.

For instance when you take a Word document saved in the older Word 2003 format (.doc), and open it in notepad you will see a lot of binary gibberish but likely you can also still see much of the actual text that is in the document. So FINDSTR would likely be able to find a match in such files. However, if you save that same document in the newer Word 2010 (.docx) format and then open it again in notepad, you may not see any of the text in the document, and you may also notice that the binary structure is completely different from the Word 2003 format. In those cases, FINDSTR will not find a match. You could still use the regular Windows Search to search inside those files. The same applies to other file formats such as .pdf, .zip, .jar, etc.

Example to search for the word “vacation” inside Word documents in the current directory:
findstr /i /m vacation *.doc

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.