Sign in to follow this  
Followers 0
schilbiz

Search file contents for string then report Filename string found in.

3 posts in this topic

Hey guys I came across this interesting script that weaponx made, I am just wondering what would need to be altered to get it to report the file it found the string in. I have tried various things but nothing seems to work.

Ultimately I am trying to peice together a script that will search the entire contents of a specific folder for a specific string of text and look in each text file for it, then display which file it was located in.

I have a few other scripts that I have been playing with that use FileFindFirstFile and FileFindNextFile and StringinStr but have not been able to get them to report the file the string was found in.

Thanks for any help offered.

#include <file.au3>
$root = "C:\test\"
$FileList = _FileListToArray($root,"*.txt")

For $X = 1 to $FileList[0]
$FileName = $root & $FileList[$X]
$String = FileRead($FileName)
$array = StringRegExp($string,"777",3)
    
    If IsArray($array) Then
     
        MsgBox(0,"", "Found it") ; display the filename it was found in.
        For $X = 0 to Ubound($array)-1
            ConsoleWrite($array[$X] & @CRLF)
        Next
    EndIf
Next

Share this post


Link to post
Share on other sites



Hey thanks Valuater it is quite the script! I tweaked the GUI a little and dropped some of the extra stuff I did not need. I kept getting an AutoIt Error: Error Allocating Memory. I narrowed the search criteria and increased my page file and got it to work. FYI: I have windows xp pro sp3 with 1G RAM and am using the most current Beta of Autoit: Version 3.2.13.3.

Again thanks for the nice script!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0