How to find the Word files in a directory containing a certain text

Hello,

I use Windows 8. I have a windows directory with a number of Word-files (.doc -files). Is it possible to search for a certain word, and get in return the doc-files in the directory containing that word?

Regards,

Arne
adiemeerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
You can do it with a Word VBA macro like this:
Sub FindWordInDocFilesInFolder()
    Dim strFileName As String
    Dim strFolder As String
    Dim j As Integer
    Dim i As Integer
    Dim strFiles() As String
    Dim doc As Document
    Dim strWord As String
    Dim strMessage As String

    strWord = "the"
    strFolder = "C:\Folder1"
   
    'process files in current folder
    strFileName = Dir$(strFolder & "\*.doc*")
    Do Until strFileName = ""
        Set doc = Documents.Open(strFolder & "\" & strFileName)
            With doc.Range.Find
                .Text = strWord
                .MatchWholeWord = True
                If .Execute() Then
                    ReDim strFiles(i)
                    strFiles(i) = strFileName
                    i = i + 1
                End If
            End With
        doc.Close wdDoNotSaveChanges
        strFileName = Dir$()
    Loop
    If i = 0 Then
        strMessage = "There are no document files in " & strFolder & " containing the word " & strWord
    Else
        strMessage = "These document files in " & strFolder & " contain the word '" & strWord & "," & vbCrLf
        For j = 0 To i - 1
            strMessage = strMessage & strFiles(j) & vbCrLf
        Next j
    End If
    MsgBox strMessage
End Sub

Open in new window

0
Shreedhar EtteCommented:
Yes, we can achive this by indexing.

For better understanding please refer this article:
http://www.tomsitpro.com/articles/windows_8_file_search-os_indexing-windows_8_indexing,2-221.html
0
[ fanpages ]IT Services ConsultantCommented:
Hi,

GrahamSkan:

The code statement...

ReDim strFiles(i)

Open in new window


I believe this would need to be...

ReDim Preserve strFiles(i)

Open in new window


BFN,

fp.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

adiemeerAuthor Commented:
Thank all for the response. I am not looking for a VB script, but actually want to use the search functionality in the windows explorer. For example selecting a directory and typing *.doc in the search box returns all the files with extension .doc. Now, I am looking for the command that returns not all the .doc files, but only the .doc files that contains a word that I specify.

Hope that my question is clear.
0
GrahamSkanRetiredCommented:
Thanks fanpages.

My quick test returned only one document of two, so I guessed that the word wasn't in the other one.

adiemeer,

It looks as if  Windows 8 indexing has improved from the mess that was Windows 7. However I don't have Windows 8. Perhaps shreedhar can be persuaded to expand on the link that (s)he provided.
0
Shreedhar EtteCommented:
GrahamSkan,

As per the question description you have mentioned Windows 8. Thats why presented you with the link.

Please help me with operating system where you want perfom search.
0
GrahamSkanRetiredCommented:
Note that this isn't my question.

Windows 8 is the OS, as is the page in you link, but the questioner seems to need some further help. I don't have Widows 8, so I can't add anything useful.

Experts-exchange is beginning to discourage relying on links as answers. It does not want to be seen as a link farm (a la BigResource)

There are other problems with external links including that fact that the target page can disappear.
0
Paul SauvéRetiredCommented:
You can do a search for a phrase by "putting this prhase" in quotation marks. However, if there is more than one file type (format) with the phrase, they will all show up in the search!

EDIT: I don't know if this has been carried over to Windows 8, but in Win7 you can add Type:docx to the search phrase to get only MS Word documents...
0
ChrisCommented:
you could try a grep tool which does simple text/string/regex searches

some options

http://astrogrep.sourceforge.net/   - free
http://stefanstools.sourceforge.net/grepWin.html - free
http://www.powergrep.com/  - at cost
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.