Jump to content

Search text and loop in multiples files


Kreg0
 Share

Recommended Posts

Hi there!

I need to add a special disclaimer in emails signatures users.
It's easy to add the message, but I want to check before if the message exist in HTML files.(My users have more than one signatures / html files)
My condition to search and stop do not works correctly, it stop on the first html file if the condition is true, but do not search and the second HTML file.
The goal is to add the message on every signature in the folder, but only one time of course. (This condition is important if the flag is not working and if we deploy the script again.)

Here is my code, what is wrong ?
 

$sFind = "</div>"
$sFilename = _FileListToArray(@AppDataDir & "\Microsoft\Signatures\", "*.htm", 1, True)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
For $i = 1 To $sFilename[0]
$search = "If you read this message, you are the winner"
Global $iLine = 0, $sLine = '', $iValid = 0
$hFile = FileOpen($sFilename[$i])

; find the line that has the search string
While 1
    $iLine += 1
    $sLine = FileReadLine($hFile)
    If @error = -1 Then ExitLoop

    ; test the line for the $search string until the flag $iValid is set
    If StringInStr($sLine, $search) And Not $iValid Then
        $iValid = 1
        ContinueLoop
    EndIf

    If $iValid Then
        $iValid += 1
        ConsoleWrite($iLine & ':' & $sLine & @CRLF)
        If $iValid = 1 Then ExitLoop
            Exit
    EndIf
WEnd
FileClose($hFile)
Next

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


For $i = 1 To $sFilename[0]

$iMsg = @CRLF
$iMsg &="<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:14.0pt;font-family:""Lucida Sans Unicode"";color:black'>If you read this message, you are the winner....</span></p>" & @CRLF
$iMsg &= "</div>" & @CRLF

$iRetval = _ReplaceStringInFile($sFilename[$i], $sFind, $iMsg)

Next

 

Thanks !!

Kreg

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...