Xonatron
Xonatron

Reputation: 16062

How do I (recursively) search ALL file contents in Windows 7?

How do I (recursively) search all file contents in Windows 7? I am using the content:xxx command, in the Search settings box in Windows Explorer, to search xxx in this example. This does not work:

As an example of how this search is broken, I see an org.eclipse.wst.common.component file with text that I am searching for and Windows 7 is not returning it in the results. I assume it's only searching known text-based file types. How can I make it search all files? I need to find everything I am looking for.

P.S. If there is a DOS-based solution, I will also accept this. Maybe a batch file using dir /s /b and findstr could be constructed.

EDIT: Noted my need for a recursive search.

Upvotes: 30

Views: 81401

Answers (6)

Bill - K5WL
Bill - K5WL

Reputation: 716

If you are looking for a GUI-based solution where you don't have to remember the syntax, try out Notepad++. There is a Search menu which lets you search files in a directory (find in files), limit it to certain extensions (filter), and look in subfolders, and then you just click on the item in the list and it opens that file for edit.

Upvotes: 38

joe
joe

Reputation: 441

"user3245549" is right:

All of the above answers with "for loops" and nested bat files are mumbo jumbo. All you need is to just use "findstr" - example:

C:\temp> findstr /S /C:"/work" * | more   <-- this will find the string "/work" in any file

or

C:\temp> findstr /S /C:"/work" "*.*" | more 

or

C:\temp> findstr /S /C:"/work" * > results.txt

or

C:\temp> findstr /S /C:"/work" "*.*" > results.txt

NOTE: You can leave out the "double-quotes" around the asterisks - I just put those because the editor here on Stackoverflow was stripping out the asterisks on either side of the period. NOTE ALSO: You still need the quotes around the "string text" for which you are searching, as far as I know.

Upvotes: 44

user3245549
user3245549

Reputation: 101

Use the findstr command from a command prompt window.

/s give you a recursive search

/i ignores case

Upvotes: 8

Pauline
Pauline

Reputation: 41

This can be done through the command prompt, though the syntax is quite verbose

for /r %a in (\*.*) do find "search_text" %a

This now works in Windows 7 (extra dot removed)

Upvotes: 4

Xonatron
Xonatron

Reputation: 16062

Here is my three file DOS solution, but I am still looking for a proper Windows 7 solution if anyone has one:

1. search.bat

@ECHO off
FOR /r %%a IN (*.*) DO CALL process.bat %%a

Searches all files recursively, and runs process.bat on each one.

2. process.bat

@ECHO Off
ECHO "%1" >> output.txt
TYPE "%1" | FINDSTR /i "search_string_here" >> output.txt

Prints out the name of each file, in quotes because some files will break the batch file code without, then finds the search string, search_string_here, and prints out the entire line that the search string is found in.

3. output.txt (sample output)

Contains the output, formatted as follows, searching search_string_here in my project_name Java project stored in D:\project_name\, displaying all files searched as well as results if there are some:

"D:\project_name\.classpath" 
"D:\project_name\.project" 
    <name>search_string_here</name>
"D:\project_name\content_search_all_files.bat" 
"D:\project_name\output.txt" 
    <name>search_string_here</name>
"D:\project_name\pom.xml" 
...

Above you can see that search_string_here was found, full line being <name>search_string_here</name>, in D:\project_name\.project file... among other results.

Again, I am still looking for a proper Windows 7 solution if anyone has one.

Warning: "Line is too long" Errors; FINDSTR may be buggy:

Apparently, FINDSTR < grep, as if you didn't know. Here's an article that dives into the error in FINDSTR that are do not reproduce when the same input is used in a different file:

Obviously, “line is too long” is a catch-all message for a number of different errors. FINDSTR has some issues. Some time ago, I said that FINDSTR was marginally useful. After today, I’d say it’s even less useful than I thought it was then. - http://blog.mischel.com/2008/10/14/copying-large-files-on-windows/

Upvotes: 5

precose
precose

Reputation: 614

If you're looking for a file or folder located in a common folder (such as Documents or Pictures), you can often find it fastest by using the Search box at the top of the folder window. For more information, see Use the Search box.Here.

If you're looking for a program, a website in your browser history, or a file that you've stored anywhere in your personal folder, you can use the Search box at the bottom of the Start menu. For more information, see Find a file or folder.Here.

If you're looking for several related files, such as all the files from a particular month, or all the documents that you have written, you can use the headings above the file list to filter, stack, or group your files. Organizing your files in one of these ways makes them easier to locate and select. For more information, see Use file list headings.Here

When you need to build a search with multiple filters, or when you're looking for files from several folders at once, create your search in the Search folder. When you are done, you can save the search criteria, and use it in the future to find the same set of files again with a single click. For more information, see Create an advanced search in the Search folder.Here

Upvotes: 0

Related Questions