Archive: Read a file Line by Line


Read a file Line by Line
Hello,

I know this is a frequently question.
I have searched through the forum, but nothing can help me to fix my issues, even This post.

Actually, in the following code, I just want to open the oemxx.inf files (concerning the drivers) and, in each of those files, i'm looking for the word "Deterministic".

The aim is to delete those specifics oemxx.inf files.

But, in my code, if I use the loop called "Lecture", the varable $4 won't be the entire line, what is what I want, but it will be each letter of the file.
I'm using the function "StrStr" which search a word in a sentence.

And, if I just donc write the two lines "Lecture:" and "Lecture", I mean I don't use the loop "Lecture", this script will give me the entire line from all oemxx.inf files.

How can I fix it, in order to be able to have all the lines of all the oemxx.inf files ???

Thank you !

Here is my code:

!include "MUI.nsh"
!define CHAINE "Deterministic"
XPStyle on
Name "Ouverture INI deux boucles"
OutFile "Ouverture INI deux boucles.exe"

!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Section "Recherche du mot clé"

DetailPrint "Les Devices sont installés dans $WINDIR\inf"
SetOutPath $WINDIR\inf
StrCpy $9 0

Open:
FileOpen $3 "$WINDIR\inf\oem$9.inf" r
MessageBox MB_OK "Ouverture de oem$9.inf - $1"
IfErrors done1

Lecture:
FileRead $3 $4
IfErrors suite
MessageBox MB_OK "$$4 - $4"
Push $4
Push ${CHAINE}
Call StrStr
Goto Lecture

suite:
FileClose $3

IntOp $9 $9 + 1
Goto Open

done1:
SectionEnd

Function StrStr
Exch $R1 ; st=tete,vieux$R1, $R1=pointeur
Exch ; st=vieux$R1,tete
Exch $R2 ; st=vieux$R1,vieux$R2, $R2=tete
Push $R3
Push $R4
Push $R5
StrLen $R3 $R1
StrCpy $R4 0
loop:
StrCpy $R5 $R2 $R3 $R4
StrCmp $R5 $R1 done
StrCmp $R5 "" done
IntOp $R4 $R4 + 1
Goto loop

done:


StrCpy $R1 $R2 "" $R4
StrCmp $R5 ${CHAINE} +1 +3
MessageBox MB_OK "Le fichier contient le mot recherché$\n$\nA la ligne : $R1"
Goto Next
MessageBox MB_OK "Le fichier ne contient pas le mot recherché"

Next:

Pop $R5
Pop $R4
Pop $R3
Pop $R2
Exch $R1

FunctionEnd


If it is a single character then that usually means the file is not encoded in ASCII but possibly unicode.

Stu