简体   繁体   中英

Windows 7 batch search for email addresses

Thanks in advance for your help. I have to do a task on my office computer which means I can't install any additional software, so I think a batch file might be the easiest way to do this even if it's not the most efficient (although I welcome other solutions that I might be able to do without installing software on my office computer). Also, please keep in mind that I have very little programming experience in your answers :)

Basically, I have a folder with a series of subfolders in it, each of these full of files of various types (text, emails, text-based pdfs, word docs). I also have a text file (or an excel column) with hundreds of email addresses in it. I want to use a batch file (or similar method) to run through each email address in the list and search against the contents of the various files in each folder like Windows Search does. Files which contain the search phrase should automatically be moved to a prespecified folder (possibly having to be renamed or put in a new subfolder as many of these files might have the same name). In the end, we should have one folder (as well as its subfolders) which contains no files which have any of the email addresses from the list in their contents, and another folder which only has files that has content containing the email addresses in their files (these can be in subfolders, or renamed, or whatever is most convenient, just not deleted).

(Since the list of email addresses is in Excel, another option I could entertain would be using some sort of VBA macro if that is capable of searching the contents of files within a folder recursively.)

I hope that this makes sense and I'm happy to clarify if it doesn't. Again, thanks for any help you can provide!

There is programming language call vbscript that's on all windows computer since windows 95. That might do the job. I think you can do that with batch. Plus it's outdated.

VBScript - Google for "VBscript search file contents"
Results such as http://www.codeproject.com/Questions/524842/VbscriptplusToplussearchplusforplusaplusstringplus should help. Also if you're having trouble with the recursive folder search part http://blogs.technet.com/b/heyscriptingguy/archive/2004/10/20/how-can-i-get-a-list-of-all-the-files-in-a-folder-and-its-subfolders.aspx might help.

VBScript is nearly identical to VBA. That code can probably be modified to run inside Excel as a macro if you'd like.

I'd recommend using FileSystemObject and TextStreams instead of native VBA file operations if you might be dealing with unicode files.

Here's a simple VBA routine which queries the windows desktop search using the ADO Provider. This script is my only experience with it to date, so if you have questions you can check here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb231256(v=vs.85).aspx

Finding the files is the relatively tricky part - moving them should be easy ;_0

Sub Tester()

    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordset = CreateObject("ADODB.Recordset")

    objConnection.Open "Provider=Search.CollatorDSO;" & _
                       "Extended Properties='Application=Windows';"

    objRecordset.Open "SELECT System.ItemName, System.ItemFolderPathDisplay " & _
                      " FROM SystemIndex" & _
                      " WHERE SCOPE = 'file:C:/_Stuff/local files' " & _
                      " and contains('joe@corp.com')", objConnection

    If Not objRecordset.EOF Then
        objRecordset.MoveFirst
        Do Until objRecordset.EOF
            With objRecordset.Fields
                Debug.Print .Item("System.ItemName"), _
                            .Item("System.ItemFolderPathDisplay")
            End With
            objRecordset.MoveNext
        Loop
    Else
        Debug.Print "no records found"
    End If

    objRecordset.Close
    Set objRecordset = Nothing
    objConnection.Close
    Set objConnection = Nothing

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM