Jump to content

Save all text from specific string


Recommended Posts

Hello,

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
    Exit
EndIf
$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
WEnd

FileClose($file)

FileWrite($iHandle,_
$save)
FileClose($iHandle)
Link to comment
Share on other sites

  • Moderators

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)
        Sleep(10)
    WEnd
    FileClose($FileSearch)
    Return $sSave
EndFunc

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...