|
![]() |
|
Thread Tools | Search this Thread | Display Modes |
![]() |
#1 |
Junior Member
Join Date: Aug 2008
Posts: 19
|
![]()
Hi there,
I'd wish to modify a text file only if a dedicated string in this file is NOT written there already. I'd like to compare each lines in a file to check if this line starts with a dedicated string, let's say a line can be: 'user is defined as blabla' and string to use for check is 'user'. so, as soon as, within a file, the script does find a line that starts with 'user' it will stop and goto another part of the script that will do 'action 1', or if it does not find any line that starts with the string 'user', it will do 'action 2'. I thought I could use ${LineFind} "[File1]" "[File2|/NUL]" "[LineNumbers]" "Function" but I have some difficulties for the 'Function', and compare process... |
![]() |
![]() |
![]() |
#2 |
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
ClearErrors
FileOpen $0 $INSTDIR\file.dat r IfErrors notfound loop: FileRead $0 $1 IfErrors goto notfound StrCpy $2 $1 4 StrCmp $2 "user" bingo goto loop end: FileClose $0 notfound: MessageBox MB_OK "Not found." goto done bingo: MessageBox MB_OK "Found." goto done done: |
![]() |
![]() |
![]() |
#3 |
Junior Member
Join Date: Aug 2008
Posts: 19
|
Thanks very much MSG for your code!
I'll test it tomorrow. |
![]() |
![]() |
![]() |
#4 |
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
Oh, and you should always FileClose. So you could move that to below the done label, I guess.
|
![]() |
![]() |
![]() |
#5 |
Junior Member
Join Date: Aug 2008
Posts: 19
|
Indeed, the FileClose was not at the best positon. I had to add anothyer one too, depending on conditions.
here is my code: code: |
![]() |
![]() |
![]() |
#6 |
Junior Member
Join Date: Aug 2008
Posts: 19
|
tested with success!
Thanks MSG |
![]() |
![]() |
![]() |
#7 |
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
Next up: Using LogicLib instead of Strcmp and goto's.
![]() |
![]() |
![]() |
![]() |
#8 |
Junior Member
Join Date: Aug 2008
Posts: 19
|
I didn't know about this one; looks cool. Thanks for the tip!
|
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|