Jump to content
Sign in to follow this  

Save all text from specific string

Recommended Posts


What i want to achief is the following. I want all .doc files in a specific dir (c:\pet) to be processed.

All .doc files have to be read until it finds string "A total of" from here on i want all the info from "A total of" until the EOF. This info (from all .doc files) i want to put in a result file. this is what i have so far.

Thx for looking in to this

$iHandle = FileOpen ('result.doc',1)

$file = FileOpen("_DailyQC_20060313.doc", 0)
If $file = -1 Then
$save = ""
; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringInStr($line, "A total of ") Then $save = $line



Share this post

Link to post
Share on other sites

Local $MainFile = @DesktopDir & '\Example', $String = 'A total of', $FileToWriteTo = @DesktopDir & '\Example\result.txt'

FileWrite($FileToWriteTo, _StringReturn($MainFile, $String))

Func _StringReturn($FileNameLocation, $sSearchString)
    Local $FileSearch = FileFindFirstFile($FileNameLocation & '\*.doc')
    Local $sSave = ''
    While 1
        $NextFile = FileFindNextFile($FileSearch)
        If @error Then ExitLoop
        $FileRead = FileRead($FileNameLocation & '\' & $NextFile, FileGetSize($FileNameLocation & '\' & $NextFile))
        $SnS = StringInStr($FileRead, $sSearchString)
        If $SnS Then $sSave &= StringMid($FileRead, $SnS + StringLen($sSearchString) + 1)
    Return $sSave

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...