brewdude6
(Hey THIS is FUN)
2004-12-10 07:51 PM
Ascan() and Readfile()

Can someone take a look at this?
Code:

$PATCHLIST="%temp%\patchlist"
$PNF="Scan"

For Each $array in ReadFile("$patchlist")
? $array
If AScan($array,$PNF) >= 0
Shell "notepad.exe"
EndIf
Next



It returns -1 but the expression is in the text file.


Howard Bullock
(KiX Supporter)
2004-12-10 07:58 PM
Re: Ascan() and Readfile()

I do not see where you open the file to read it. Chack the manual for "OPEN"

Ascan works on Arrays. I do not see where you have an array. $array in your example would normally be an ELEMENT of an ARRAY.


----------------

Scratch above as I misread ReadFile to be Readline. Still looking...


Howard Bullock
(KiX Supporter)
2004-12-10 08:04 PM
Re: Ascan() and Readfile()

This should be more correct.
Code:
$PATCHLIST="%temp%\patchlist"

$PNF="Scan"
If AScan(ReadFile($patchlist),$PNF) >= 0
Shell "notepad.exe"
EndIf



LonkeroAdministrator
(KiX Master Guru)
2004-12-10 08:08 PM
Re: Ascan() and Readfile()

yeah.

brewdude6
(Hey THIS is FUN)
2004-12-10 08:32 PM
Re: Ascan() and Readfile()

Thanks, but that still returns -1

Howard Bullock
(KiX Supporter)
2004-12-10 08:41 PM
Re: Ascan() and Readfile()

Time to perform more debugging and providing answers.

Code:
$PATCHLIST="%temp%\patchlist"
$aLines = ReadFile($patchlist)
? "Number of elements = " + (Ubound($aLines) + 1)
? "Ascan = " + AScan($aLines,$PNF)

for each $line in $aLines
? "'" + $line + "'"
next
; Is 'Scan' output?
; Do you have CaseSensitivity turned on?

$PNF="Scan"

If AScan($aLines,$PNF) >= 0
Shell "notepad.exe"
EndIf




brewdude6
(Hey THIS is FUN)
2004-12-10 09:49 PM
Re: Ascan() and Readfile()

Thanks Howard...that helped me realize that each line is a string and not each word in each line (at least I think that's the case). $PNF is in one of the lines, just not the only word.

Howard Bullock
(KiX Supporter)
2004-12-10 10:08 PM
Re: Ascan() and Readfile()

Then try this...
Code:
$PATCHLIST="%temp%\patchlist"
$aLines = ReadFile($patchlist)
$TextOfFile = join($aLines, @CRLF)
$PNF="Scan"

If instr($TextOfFile,$PNF) >= 0
Shell "notepad.exe"
EndIf



LonkeroAdministrator
(KiX Master Guru)
2004-12-10 10:25 PM
Re: Ascan() and Readfile()

or:
Code:

$PATCHLIST="%temp%\patchlist"
$aLines = ReadFile($patchlist)
$TextOfFile = split(join($aLines))
$PNF="Scan"
If -1<ascan($TextOfFile,$PNF)
Shell "notepad.exe"
EndIf



brewdude6
(Hey THIS is FUN)
2004-12-10 10:35 PM
Re: Ascan() and Readfile()

I better include the whole script I'm testing with.

test.txt
Code:

test
this
on
a
system




Code:
 
$PATCHLIST="c:\temp\test.txt"
$aLines = ReadFile($patchlist)
$TextOfFile = Join($aLines, @CRLF)
$PNF="test"
If InStr($TextOfFile,$PNF) >= 0
Shell "notepad.exe"
EndIf

Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=Chr(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @error Exit @error EndIf
Do $t=$t+$lf+ReadLine($f) Until @error
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction



Even if I use a word not in text.txt, notepad will execute. I'm obviously in over my head, but it's only waist deep.


brewdude6
(Hey THIS is FUN)
2004-12-10 10:36 PM
Re: Ascan() and Readfile()

Yes...that works. Thank you all.

Howard Bullock
(KiX Supporter)
2004-12-10 10:38 PM
Re: Ascan() and Readfile()

My mistake.
If InStr($TextOfFile,$PNF) >= 0

should be

If InStr($TextOfFile,$PNF) > 0

Instr returns 0 if not found. That code was a holdover from the ASCAN where you needed zero.


maciep
(Korg Regular)
2004-12-10 10:42 PM
Re: Ascan() and Readfile()

or just plain

If InStr($TextOfFile,$PNF)


Howard Bullock
(KiX Supporter)
2004-12-10 10:45 PM
Re: Ascan() and Readfile()

Simpler is indeed better. Not sure why I wrote it that way.

LonkeroAdministrator
(KiX Master Guru)
2004-12-10 10:52 PM
Re: Ascan() and Readfile()

specially as the joinsplitter is in use now and that is irrelevant.

could do some golfing though:
Code:

$PATCHLIST="%temp%\patchlist"
$PNF="Scan"
If -1<ascan(split(join(ReadFile($patchlist))),$PNF)
Shell "notepad.exe"
EndIf